From 98231152400a6c496fc6e27175041c298798be3e Mon Sep 17 00:00:00 2001 From: yusank Date: Sun, 5 Jun 2022 20:13:43 +0800 Subject: [PATCH] fix: application --- pkg/app/application.go | 14 ++++++++++++++ pkg/config/config.go | 3 +-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/app/application.go b/pkg/app/application.go index f12da47..a155420 100644 --- a/pkg/app/application.go +++ b/pkg/app/application.go @@ -16,6 +16,7 @@ import ( "github.com/go-kratos/kratos/v2/transport/http" redisv8 "github.com/go-redis/redis/v8" + "github.com/go-goim/core/pkg/cmd" "github.com/go-goim/core/pkg/config" "github.com/go-goim/core/pkg/db/mysql" "github.com/go-goim/core/pkg/db/redis" @@ -65,6 +66,14 @@ func WithMetadata(k, v string) Option { } } +var ( + useHostIP bool +) + +func init() { + cmd.GlobalFlagSet.BoolVar(&useHostIP, "use-host-ip", true, "use host ip") +} + var ( initFlag atomic.Bool ) @@ -128,6 +137,11 @@ func InitApplication(opts ...Option) (*Application, error) { } func (a *Application) initHost() error { + if !useHostIP { + a.host = "" + return nil + } + addrs, err := net.InterfaceAddrs() if err != nil { return err diff --git a/pkg/config/config.go b/pkg/config/config.go index 99417c8..85d533a 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -119,9 +119,8 @@ func InitConfig() *Config { panic(err) } - log.Debug("service content", "service", cfg) - cfg.SrvConfig = sc + log.Debug("service content", "service", cfg) } setLogger(cfg.SrvConfig.Name, cfg.SrvConfig.Log)