diff --git a/tars/config.go b/tars/config.go index 39dba6ce..a2d11d5d 100755 --- a/tars/config.go +++ b/tars/config.go @@ -1,6 +1,8 @@ package tars import ( + "fmt" + "strings" "time" "github.com/TarsCloud/TarsGo/tars/util/endpoint" @@ -101,6 +103,24 @@ func GetClientConfig() *clientConfig { return defaultApp.ClientConfig() } +func (c *clientConfig) ValidateStat() error { + if c.Stat == "" || (c.LocatorEmpty() && !strings.Contains(c.Stat, "@")) { + return fmt.Errorf("stat config emptry") + } + return nil +} + +func (c *clientConfig) ValidateProperty() error { + if c.Property == "" || (c.LocatorEmpty() && !strings.Contains(c.Property, "@")) { + return fmt.Errorf("property config emptry") + } + return nil +} + +func (c *clientConfig) LocatorEmpty() bool { + return c.Locator == "" +} + // ServerConfig returns server config func (a *application) ServerConfig() *serverConfig { a.init() diff --git a/tars/propertyf.go b/tars/propertyf.go index a20a85b3..3edfa817 100755 --- a/tars/propertyf.go +++ b/tars/propertyf.go @@ -1,7 +1,6 @@ package tars import ( - "fmt" "reflect" "sort" "strconv" @@ -326,14 +325,19 @@ var ( proOnce utilSync.Once ) +func newPropertyReportHelper(comm *Communicator, node string) *PropertyReportHelper { + p := new(PropertyReportHelper) + p.Init(comm, node) + return p +} + func initProReport() error { cfg := GetClientConfig() - if cfg.Property == "" || (cfg.Locator == "" && !strings.Contains(cfg.Property, "@")) { - return fmt.Errorf("property emptry") + if err := cfg.ValidateProperty(); err != nil { + return err } comm := GetCommunicator() - ProHelper = new(PropertyReportHelper) - ProHelper.Init(comm, GetClientConfig().Property) + ProHelper = newPropertyReportHelper(comm, cfg.Property) go ProHelper.Run() return nil } diff --git a/tars/statf.go b/tars/statf.go index 6220b656..7685d24d 100755 --- a/tars/statf.go +++ b/tars/statf.go @@ -170,9 +170,9 @@ var ( func initReport(app *application) error { cfg := app.ClientConfig() - if cfg.Stat == "" || (cfg.Locator == "" && !strings.Contains(cfg.Stat, "@")) { + if err := cfg.ValidateStat(); err != nil { statInited <- struct{}{} - return fmt.Errorf("stat init error") + return err } comm := app.Communicator() StatReport = new(StatFHelper)