package conf import ( "encoding/json" "errors" "fmt" "os" "strings" "github.com/aceld/zinx/zconf" "github.com/aceld/zinx/zlog" ) type Channel struct { TCPPort int `json:"tcp_port"` //当前通道的TCP监听端口 BindFlag string `json:"bind_flag"` //当前通道bind 的网元信息 Province string `json:"province"` //网元所在省份 DeviceCode string `json:"device_code"` //主机编码 四位,每1位可用0-9、A-Z编码 } type Config struct { // 网元通道 Channel []Channel `json:"channel"` // 数据库连接 Mysql string `json:"mysql"` //以下是zinx 的配置 Name string `json:"name"` MaxConn int `json:"max_conn"` WorkerPoolSize int `json:"worker_pool_size"` HeartbeatMax int `json:"heartbeat_max"` HbcheckInterval int `json:"hbcheck_interval"` LogDir string `json:"log_dir"` LogFile string `json:"log_file"` // FTP文件服务 FTPRoot string `json:"ftp_root"` } var OmcConf Config func Reload(path string) error { confFileExists, _ := zconf.PathExists(path) if !confFileExists { zlog.Ins().ErrorF("Config File %s is not exist!!", path) return errors.New("config file is not exist") } data, err := os.ReadFile(path) if err != nil { return err } err = json.Unmarshal(data, &OmcConf) if err != nil { return err } return nil } func Init(path string) { if path == "" || strings.HasSuffix(path, "zinx.json") { pwd, err := os.Getwd() if err != nil { pwd = "." } path = pwd + "/conf/nbi_alarm.json" fmt.Println("path", path) } if err := Reload(path); err != nil { zlog.Ins().ErrorF("Config File %s error, ", err) panic(err) } }