同步代码
This commit is contained in:
75
conf/global.go
Normal file
75
conf/global.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package conf
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/aceld/zinx/zconf"
|
||||
"github.com/aceld/zinx/zlog"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
/*
|
||||
Server
|
||||
*/
|
||||
Mysql string `json:"mysql"`
|
||||
FTPRoot string `json:"ftp_root"`
|
||||
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编码
|
||||
} `json:"channel"`
|
||||
|
||||
//以下是zinx 的配置
|
||||
Name string `json:"name"`
|
||||
MaxConn int `json:"max_conn"`
|
||||
WorkerPoolSize int `json:"worker_pool_size"`
|
||||
HeartbeatMax int `json:"heartbeat_max"`
|
||||
LogDir string `json:"log_dir"`
|
||||
LogFile string `json:"log_file"`
|
||||
}
|
||||
|
||||
var OmcConf Config
|
||||
|
||||
const ConfPath = "/conf/nbi_alarm_agent.json"
|
||||
|
||||
func Reload(path string) error {
|
||||
if confFileExists, _ := zconf.PathExists(path); confFileExists != true {
|
||||
zlog.Ins().ErrorF("Config File %s is not exist!!", path)
|
||||
return errors.New("config file is not exist")
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(data, &OmcConf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Init(path string) {
|
||||
fmt.Println("filePath:", path)
|
||||
if path == "" {
|
||||
pwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
pwd = "."
|
||||
}
|
||||
path = pwd + ConfPath
|
||||
fmt.Println("path", path)
|
||||
}
|
||||
|
||||
if err := Reload(path); err != nil {
|
||||
zlog.Ins().ErrorF("Config File %s error, ", err)
|
||||
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
//"mysql": "root:1000omc@kp!@tcp(192.168.2.119:33066)/omc_db?charset=utf8mb4&parseTime=True&loc=Local",
|
||||
22
conf/nbi_alarm_agent.json
Normal file
22
conf/nbi_alarm_agent.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"channel": [
|
||||
{
|
||||
"tcp_port": 31232,
|
||||
"bind_flag": "SMF#SZ_01",
|
||||
"province": "BJ",
|
||||
"device_code": "0001"
|
||||
},
|
||||
{
|
||||
"tcp_port": 31233,
|
||||
"bind_flag": "UDM#SZ_03",
|
||||
"province": "BJ",
|
||||
"device_code": "0002"
|
||||
}
|
||||
],
|
||||
"mysql": "root:1000omc@kp!@tcp(192.168.0.229:33066)/omc_db?charset=utf8mb4&parseTime=True&loc=Local",
|
||||
"ftp_root": "data/ftp",
|
||||
"mame":"nbi north alarm agent",
|
||||
"heartbeat_max": 180,
|
||||
"log_dir": "./nbi_alarm",
|
||||
"log_file":"nbi_alarm.log"
|
||||
}
|
||||
Reference in New Issue
Block a user