diff --git a/config/config.go b/config/config.go index 3a87e99..12e68c3 100644 --- a/config/config.go +++ b/config/config.go @@ -6,7 +6,6 @@ import ( "github.com/OpenIoTHub/utils/models" "gopkg.in/yaml.v2" "io" - "io/ioutil" "log" "os" "path/filepath" @@ -32,7 +31,8 @@ func LoadConfig() (err error) { writers = append(writers, os.Stdout) } if ConfigMode.LogConfig != nil && ConfigMode.LogConfig.LogFilePath != "" { - f, err := os.OpenFile(ConfigMode.LogConfig.LogFilePath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644) + var f *os.File + f, err = os.OpenFile(ConfigMode.LogConfig.LogFilePath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644) if err != nil { log.Fatal(err) } @@ -111,6 +111,6 @@ func writeConfigFile(configMode models.ServerConfig, path string) (err error) { if err != nil { return } - err = ioutil.WriteFile(path, configByte, 0644) + err = os.WriteFile(path, configByte, 0644) return } diff --git a/manager/grpc.go b/manager/grpc.go index 53220a9..53d5a04 100644 --- a/manager/grpc.go +++ b/manager/grpc.go @@ -18,7 +18,13 @@ import ( // grpc func (sm *SessionsManager) StartgRpcListenAndServ() { go func() { - s := grpc.NewServer(grpc.Creds(credentials.NewTLS(autocertManager.TLSConfig()))) + //TODO 如果是IP则使用不安全的连接,如果是域名则使用安全的连接 + var s *grpc.Server + if net.ParseIP(config.ConfigMode.PublicIp) == nil { + s = grpc.NewServer(grpc.Creds(credentials.NewTLS(autocertManager.TLSConfig()))) + } else { + s = grpc.NewServer() + } pb.RegisterHttpManagerServer(s, sm) lis, err := net.Listen("tcp", fmt.Sprintf(":%d", config.ConfigMode.Common.GrpcPort)) if err != nil {