package metric import ( "errors" ) var ( serv *service ) type Config struct { Address string Token string Interval int } func NewConfg() *Config { return &Config{ Address: "http://t.batiao8.com", Interval: 10, } } func Init(c *Config) error { if serv != nil { return nil } if c == nil { return errors.New("metric config is nil") } if c.Address == "" { return errors.New("metric address is required") } if c.Token == "" { return errors.New("metric token is required") } if c.Interval <= 0 { c.Interval = 10 } serv = newService(c) go serv.run() return nil }