github.com/sereiner/library@v0.0.0-20200518095232-1fa3e640cc5f/queue/xmq/xmq.conf.go (about) 1 package xmq 2 3 import ( 4 "encoding/json" 5 "fmt" 6 7 "github.com/asaskevich/govalidator" 8 ) 9 10 type Conf struct { 11 Address string `json:"address" valid:"dialstring,required"` 12 Key string `json:"key"` 13 } 14 15 func NewConf(j string) (*Conf, error) { 16 conf := Conf{} 17 err := json.Unmarshal([]byte(j), &conf) 18 if err != nil { 19 return nil, err 20 } 21 if b, err := govalidator.ValidateStruct(&conf); !b { 22 err = fmt.Errorf("xmq 配置文件有误:%v", err) 23 return nil, err 24 } 25 return &conf, nil 26 }