feat(storage): add conf addr

This commit is contained in:
bandl 2021-09-05 17:08:35 +08:00
parent 6b80b30f31
commit aadb43cfd9
1 changed files with 12 additions and 1 deletions

View File

@ -9,9 +9,11 @@ import (
"os/signal"
"syscall"
_ "gitee.com/timedb/wheatCache/conf"
"gitee.com/timedb/wheatCache/storage/proto"
"gitee.com/timedb/wheatCache/storage/server"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
@ -24,7 +26,16 @@ var rootCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
storageServer := server.NewServer()
// 先写死, 等配置文件
listen, err := net.Listen("tcp", ":5201")
conf := viper.GetStringMap("storage")
host := conf["host"].(string)
port := conf["port"].(int)
tcpAddr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", host, port))
if err != nil {
log.Fatalln(err)
}
listen, err := net.ListenTCP("tcp", tcpAddr)
if err != nil {
log.Panicln(err)
}