From aadb43cfd9d012ccffdca7029b24df61aa102602 Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Sun, 5 Sep 2021 17:08:35 +0800 Subject: [PATCH] feat(storage): add conf addr --- storage/cmd/root.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/storage/cmd/root.go b/storage/cmd/root.go index dc5f5a4..0a6b201 100644 --- a/storage/cmd/root.go +++ b/storage/cmd/root.go @@ -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) }