12345678910111213141516171819202122 |
- package options
- import (
- "github.com/nats-io/nats.go"
- "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/log"
- )
- type NatsOption struct {
- Enable bool `json:"enable" mapstructure:"enable"`
- Url string `json:"url" mapstructure:"url"`
- }
- func InitNats(natsOption NatsOption) *nats.Conn {
- if !natsOption.Enable {
- return nil
- }
- conn, err := nats.Connect("nats://" + natsOption.Url)
- if err != nil {
- log.Panicf("初始化NATS失败:%s", err)
- }
- return conn
- }
|