配置文件

This commit is contained in:
TsMask
2023-08-21 18:47:48 +08:00
parent d87979ff3d
commit 8f128b6c73
2 changed files with 57 additions and 26 deletions

View File

@@ -4,18 +4,15 @@ import (
"encoding/json"
"errors"
"fmt"
"os"
"strings"
"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 的网元信息
@@ -23,13 +20,20 @@ type Config struct {
DeviceCode string `json:"device_code"` //主机编码 四位每1位可用0-9、A-Z编码
} `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"`
LogDir string `json:"log_dir"`
LogFile string `json:"log_file"`
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"`
//证书配置
CA struct {
@@ -42,15 +46,14 @@ type Config struct {
var OmcConf Config
const ConfPath = "/conf/nbi_alarm_agent.json"
func Reload(path string) error {
if confFileExists, _ := zconf.PathExists(path); confFileExists != true {
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 := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
return err
}
@@ -63,13 +66,12 @@ func Reload(path string) error {
}
func Init(path string) {
fmt.Println("filePath:", path)
if path == "" {
if path == "" || strings.HasSuffix(path, "zinx.json") {
pwd, err := os.Getwd()
if err != nil {
pwd = "."
}
path = pwd + ConfPath
path = pwd + "/conf/nbi_alarm_agent.json"
fmt.Println("path", path)
}
@@ -79,5 +81,3 @@ func Init(path string) {
panic(err)
}
}
//"mysql": "root:1000omc@kp!@tcp(192.168.2.119:33066)/omc_db?charset=utf8mb4&parseTime=True&loc=Local",

View File

@@ -2,23 +2,54 @@
"channel": [
{
"tcp_port": 31232,
"bind_flag": "SMF#SZ_01",
"bind_flag": "SMF#1101RJHX1SMF01",
"province": "BJ",
"device_code": "0001"
},
{
"tcp_port": 31233,
"bind_flag": "UDM#SZ_03",
"bind_flag": "UDM#1101RJHX1UDM01",
"province": "BJ",
"device_code": "0002"
},
{
"tcp_port": 31234,
"bind_flag": "AUSF#1101RJHX1AUF01",
"province": "BJ",
"device_code": "0003"
},
{
"tcp_port": 31235,
"bind_flag": "AMF#1101RJHX1AMF01",
"province": "BJ",
"device_code": "0004"
},
{
"tcp_port": 31236,
"bind_flag": "UPF#1101RJHX1UPF01",
"province": "BJ",
"device_code": "0005"
},
{
"tcp_port": 31237,
"bind_flag": "AMF#1101RJHX1AMF03",
"province": "BJ",
"device_code": "0006"
}
],
"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",
"max_conn": 3000,
"worker_pool_size": 100,
"heartbeat_max": 180,
"log_dir": "./nbi_alarm",
"hbcheck_interval": 60,
"log_dir": "./assets/nbi_alarm",
"log_file":"nbi_alarm.log",
"ftp_root": "data/ftp",
"ca":{
"root_cert":"ca/CA/demoCA/cacert.pem",
"cert":"/ca/CA/certs/test1.crt",