配置文件

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" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"os"
"strings"
"github.com/aceld/zinx/zconf" "github.com/aceld/zinx/zconf"
"github.com/aceld/zinx/zlog" "github.com/aceld/zinx/zlog"
"io/ioutil"
"os"
) )
type Config struct { type Config struct {
/* // 网元通道
Server
*/
Mysql string `json:"mysql"`
FTPRoot string `json:"ftp_root"`
Channel []struct { Channel []struct {
TCPPort int `json:"tcp_port"` //当前通道的TCP监听端口 TCPPort int `json:"tcp_port"` //当前通道的TCP监听端口
BindFlag string `json:"bind_flag"` //当前通道bind 的网元信息 BindFlag string `json:"bind_flag"` //当前通道bind 的网元信息
@@ -23,13 +20,20 @@ type Config struct {
DeviceCode string `json:"device_code"` //主机编码 四位每1位可用0-9、A-Z编码 DeviceCode string `json:"device_code"` //主机编码 四位每1位可用0-9、A-Z编码
} `json:"channel"` } `json:"channel"`
// 数据库连接
Mysql string `json:"mysql"`
//以下是zinx 的配置 //以下是zinx 的配置
Name string `json:"name"` Name string `json:"name"`
MaxConn int `json:"max_conn"` MaxConn int `json:"max_conn"`
WorkerPoolSize int `json:"worker_pool_size"` WorkerPoolSize int `json:"worker_pool_size"`
HeartbeatMax int `json:"heartbeat_max"` HeartbeatMax int `json:"heartbeat_max"`
LogDir string `json:"log_dir"` HbcheckInterval int `json:"hbcheck_interval"`
LogFile string `json:"log_file"` LogDir string `json:"log_dir"`
LogFile string `json:"log_file"`
// FTP文件服务
FTPRoot string `json:"ftp_root"`
//证书配置 //证书配置
CA struct { CA struct {
@@ -42,15 +46,14 @@ type Config struct {
var OmcConf Config var OmcConf Config
const ConfPath = "/conf/nbi_alarm_agent.json"
func Reload(path string) error { 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) zlog.Ins().ErrorF("Config File %s is not exist!!", path)
return errors.New("config file is not exist") return errors.New("config file is not exist")
} }
data, err := ioutil.ReadFile(path) data, err := os.ReadFile(path)
if err != nil { if err != nil {
return err return err
} }
@@ -63,13 +66,12 @@ func Reload(path string) error {
} }
func Init(path string) { func Init(path string) {
fmt.Println("filePath:", path) if path == "" || strings.HasSuffix(path, "zinx.json") {
if path == "" {
pwd, err := os.Getwd() pwd, err := os.Getwd()
if err != nil { if err != nil {
pwd = "." pwd = "."
} }
path = pwd + ConfPath path = pwd + "/conf/nbi_alarm_agent.json"
fmt.Println("path", path) fmt.Println("path", path)
} }
@@ -79,5 +81,3 @@ func Init(path string) {
panic(err) 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": [ "channel": [
{ {
"tcp_port": 31232, "tcp_port": 31232,
"bind_flag": "SMF#SZ_01", "bind_flag": "SMF#1101RJHX1SMF01",
"province": "BJ", "province": "BJ",
"device_code": "0001" "device_code": "0001"
}, },
{ {
"tcp_port": 31233, "tcp_port": 31233,
"bind_flag": "UDM#SZ_03", "bind_flag": "UDM#1101RJHX1UDM01",
"province": "BJ", "province": "BJ",
"device_code": "0002" "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", "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", "mame":"nbi north alarm agent",
"max_conn": 3000,
"worker_pool_size": 100,
"heartbeat_max": 180, "heartbeat_max": 180,
"log_dir": "./nbi_alarm", "hbcheck_interval": 60,
"log_dir": "./assets/nbi_alarm",
"log_file":"nbi_alarm.log", "log_file":"nbi_alarm.log",
"ftp_root": "data/ftp",
"ca":{ "ca":{
"root_cert":"ca/CA/demoCA/cacert.pem", "root_cert":"ca/CA/demoCA/cacert.pem",
"cert":"/ca/CA/certs/test1.crt", "cert":"/ca/CA/certs/test1.crt",