From d7adfa79ba79ce387972b1f580e419e3536146bc Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Tue, 15 Jul 2025 14:45:45 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E7=A7=BB=E9=99=A4=E6=8E=89=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E9=85=8D=E7=BD=AE=E7=B2=BE=E7=AE=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/default/omc.yaml | 172 +++----------------------- local/omc.yaml | 219 ++++++++------------------------- src/config/config.default.yaml | 25 +++- src/config/config.local.yaml | 56 ++++----- src/config/config.prod.yaml | 32 +++-- src/framework/config/config.go | 43 +------ 6 files changed, 142 insertions(+), 405 deletions(-) diff --git a/build/default/omc.yaml b/build/default/omc.yaml index c1a1dae6..2da64727 100644 --- a/build/default/omc.yaml +++ b/build/default/omc.yaml @@ -7,21 +7,15 @@ serverVersion: "std" # interface encryption, default false # serverCryptoApi: false - +# route service configuration # service listen ipv4/v6 and port, support multiple routines -# ip: 0.0.0.0 or ::0, support IPv4/v6 -server: - - ipv4: 0.0.0.0 - ipv6: "" - port: 33030 # http listen port - schema: http - - ipv4: 0.0.0.0 - ipv6: "" - port: 33443 # https listen port - schema: https - certFile: /usr/local/etc/omc/certs/www.omc.net.crt - keyFile: /usr/local/etc/omc/certs/www.omc.net.key - +routeServer: + - addr: "0.0.0.0:33030" # route http port + schema: "http" + - addr: "0.0.0.0:33443" # route https port + schema: "https" + certFile: "/usr/local/etc/omc/certs/www.omc.net.crt" + keyFile: "/usr/local/etc/omc/certs/www.omc.net.key" # web service configuration # if you are using nginx to take over, you can disable the @@ -29,12 +23,12 @@ webServer: enabled: true # web server enabled, default false rootDir: /usr/local/etc/omc/web listen: - - addr: 0.0.0.0:80 - schema: http - - addr: 0.0.0.0:443 - schema: https - certFile: /usr/local/etc/omc/certs/www.omc.net.crt - keyFile: /usr/local/etc/omc/certs/www.omc.net.key + - addr: "0.0.0.0:80" # web http port + schema: "http" + - addr: "0.0.0.0:443" # web https port + schema: "https" + certFile: "/usr/local/etc/omc/certs/www.omc.net.crt" + keyFile: "/usr/local/etc/omc/certs/www.omc.net.key" # track configuration for NE signaling trace # host fill in the specific IP address @@ -61,7 +55,6 @@ database: # default data source name defaultDataSourceName: "std" - # redis cached data redis: dataSource: @@ -73,136 +66,11 @@ redis: # default data source name defaultDataSourceName: "default" - -# file: log file name -# level: /trace/debug/info/warn/error/fatal, default: debug -# duration: rotation time with xx hours, example: 1/12/24 hours -# count: rotation count of log, default is 30 rotation +# log logger: - file: /var/log/omc_restagent.log - level: warn - duration: 24 - count: 90 + fileDir: "/var/log" # Log File Dir + fileName: "omc.log" # Log File Name + level: 2 # Log Level of 0:silent<1:info<2:warn<3:error + maxDay: 7 # Log retention Days + maxSize: 10 # Log File cutting by size -# sleep: time delay for after write buffer (millisecond) -# deadLine: timeout for io read and write (second) -mml: - sleep: 200 - deadLine: 10 - sizeRow: 600 - sizeCol: 128 - bufferSize: 65535 - mmlHome: ./mmlhome - -# NE config -ne: - user: omcuser - etcdir: /usr/local/etc - bindir: /usr/local/bin - omcdir: /usr/local/omc - scpdir: /tmp - licensedir: /usr/local/etc/{neType}/license - # backup etc list of IMS, does not contain spaces - etcListIMS: "{*.yaml,mmtel,vars.cfg}" - etcListDefault: "{*.yaml,*.conf,*.cfg}" - # true/false to overwrite config file when dpkg ne software - dpkgOverwrite: false - # dpkg timeout (second) - dpkgTimeout: 180 - -# chk2ne: true/false, if put OmcNeConfig parameters to NE -omc: - uriPrefix: "/omc/rest" - neType: OMC - neId: 001 - rmUID: 4400HX101 - neName: OMC - province: "" - vendor: "" - dn: "" - chk2ne: false - capability: 50 - sn: "-" - expiryDate: "-" - checksign: false - rootDir: /usr/local/omc - binDir: /usr/local/omc/bin - backup: /usr/local/omc/backup - upload: /usr/local/omc/upload - frontUpload: /usr/local/omc/htdocs/front/upload - frontTraceDir: /usr/local/omc/htdocs/front/trace - software: /usr/local/omc/software - license: /usr/local/omc/license - gtpUri: gtp:192.168.2.119:32152 - checkContentType: false - testMode: false - rbacMode: true - runDir: /usr/local/omc/run - cmdTimeout: 120 - -# Alarm module setting -# Forward interface: -# TLS Skip verify: true/false -# email/sms -# smProxy: sms(Short Message Service)/smsc(SMS Centre) -# dataCoding: 0:GSM7BIT, 1:ASCII, 2:BINARY8BIT1, 3:LATIN1, -# 4:BINARY8BIT2, 6:CYRILLIC, 7:HEBREW, 8:UCS2 -alarm: - alarmEmailForward: - enable: false - emailList: "" - title: "Alarm from OMC" - smtp: mail.smtp.com - port: 25 - user: smtpext@smtp.com - password: "1000smtp@omc!" - tlsSkipVerify: true - alarmSMSForward: - enable: false - mobileList: "" - smscAddr: "192.168.13.114:2775" - systemID: "omc" - password: "omc123" - systemType: "UTRAN" - dataCoding: 0 - serviceNumber: "OMC" - sms: - apiURL: http://smsc.xxx.com/ - accessKeyID: xxxx - accessKeySecret: xxxx - signName: xxx SMSC - templateCode: 1000 - smProxy: smsc - -# User authorized information -# crypt: mysql/md5/bcrypt -# token: true/false to check accessToken -# expires for session, unit: second -# Support single/multiple session of user -# -auth: - crypt: bcrypt - token: true - expires: 1800 - session: multiple - publicKey: /usr/local/omc/etc/certs/omc - privateKey: /usr/local/omc/etc/certs/omc - -# Parameter for limit number -# rmuid_maxnum: the max number of rmUID, default: 50 -# alarmid_maxnum: the max number of AlarmID, default: 50 -# pmid_maxnum: the max number of pmID, default: 50 -# subid_maxnum: the max number of subscription ID, default: 20 -# uri_maxlen: the max length of uri, default: 8192 -# rmuid_regexp: regexp pattern of rmUID -params: - rmuidmaxnum: 50 - alarmidmaxnum: 50 - pmidmaxnum: 50 - subidmaxnum: 20 - urimaxlen: 2100000 - rmuidregexp: "[0-9]{4}[A-Z]{2}[A-Z]{2}[0-9A-Z]{1}[0-9A-Z]{3}[0-9A-Z]{1,16}" - -testConfig: - enabled: false - file: /usr/local/omc/etc/testconfig.yaml diff --git a/local/omc.yaml b/local/omc.yaml index f2adc98e..d4987cca 100644 --- a/local/omc.yaml +++ b/local/omc.yaml @@ -7,32 +7,28 @@ serverVersion: "std" # interface encryption, default false # serverCryptoApi: false +# route service configuration # service listen ipv4/v6 and port, support multiple routines -# ip: 0.0.0.0 or ::0, support IPv4/v6 -server: - - ipv4: "0.0.0.0" - ipv6: "" - port: 33040 # http listen port - schema: http - - ipv4: "0.0.0.0" - ipv6: "" - port: 33443 # https listen port - schema: https - certFile: ./local/certs/www.omc.net.crt - keyFile: ./local/certs/www.omc.net.key +routeServer: + - addr: "0.0.0.0:33040" # route http port + schema: "http" + - addr: "0.0.0.0:33443" # route https port + schema: "https" + certFile: "./local/certs/www.omc.net.crt" + keyFile: "./local/certs/www.omc.net.key" # web service configuration # if you are using nginx to take over, you can disable the webServer: enabled: false # web server enabled, default false - rootDir: ./local/web + rootDir: /usr/local/etc/omc/web listen: - - addr: "0.0.0.0:80" - schema: http - - addr: "0.0.0.0:443" - schema: https - certFile: ./local/certs/www.omc.net.crt - keyFile: ./local/certs/www.omc.net.key + - addr: "0.0.0.0:80" # web http port + schema: "http" + - addr: "0.0.0.0:443" # web https port + schema: "https" + certFile: "./local/certs/www.omc.net.crt" + keyFile: "./local/certs/www.omc.net.key" # track configuration for NE signaling trace # host fill in the specific IP address @@ -41,46 +37,42 @@ trace: host: "192.168.5.58" # trace host, default 127.0.0.1 port: 33033 # trace port, default 33033 -# data sources +# data source database: dataSource: - # Default database instance + # std: standard std: type: "mysql" - host: "192.168.9.58" - port: 13306 - username: "root" - password: "1000omc@kp!" - database: "omc_db_mainv2" - logging: true - # SQLite database instance + host: "192.168.9.58" # mysql host + port: 13306 # mysql port + username: "root" # mysql username + password: "1000omc@kp!" # mysql password + database: "omc_db_mainv2" # mysql database + # lite: lite lite: type: "sqlite" - database: "./local/omc_db.sqlite" - logging: true - # used to specify the default data source for multiple data resourece + database: "./local/omc_db.sqlite" # sqlite database + # default data source name defaultDataSourceName: "std" # redis cached data redis: dataSource: default: - port: 16379 # port - host: "192.168.9.58" # host - password: "helloearth" - db: 10 # db_num + port: 16379 # redis port + host: "192.168.9.58" # redis host + password: "helloearth" # redis password + db: 10 # Redis db_num # default data source name defaultDataSourceName: "default" -# file: log file name -# level: /trace/debug/info/warn/error/fatal, default: debug -# duration: rotation time with xx hours, example: 1/12/24 hours -# count: rotation count of log, default is 30 rotation +# log logger: - file: "C:/var/log/omc_restagent.log" - level: warn - duration: 24 - count: 90 + fileDir: "/var/log" # Log File Dir + fileName: "omc.log" # Log File Name + level: 0 # Log Level of 0:silent<1:info<2:warn<3:error + maxDay: 7 # Log retention Days + maxSize: 10 # Log File cutting by size # prometheus metrics metrics: true @@ -98,125 +90,22 @@ staticFile: prefix: "/upload" dir: "C:/usr/local/omc/upload" -# sleep: time delay for after write buffer (millisecond) -# deadLine: timeout for io read and write (second) -mml: - sleep: 200 - deadLine: 10 - sizeRow: 600 - sizeCol: 128 - bufferSize: 65535 - mmlHome: ./mmlhome - -# NE config -ne: - user: omcuser - etcdir: /usr/local/etc - bindir: /usr/local/bin - omcdir: /usr/local/omc - scpdir: /tmp - licensedir: /usr/local/etc/{neType}/license - # backup etc list of IMS, does not contain spaces - etcListIMS: "{*.yaml,mmtel,vars.cfg}" - etcListDefault: "{*.yaml,*.conf,*.cfg}" - # true/false to overwrite config file when dpkg ne software - dpkgOverwrite: false - # dpkg timeout (second) - dpkgTimeout: 180 - -# chk2ne: true/false, if put OmcNeConfig parameters to NE -omc: - uriPrefix: "/omc/rest" - neType: OMC - neId: 001 - rmUID: 4400HX101 - neName: OMC - province: "" - vendor: "" - dn: "" - chk2ne: false - capability: 50 - sn: "12345678" - expiryDate: "2099-12-31" - checksign: false - rootDir: /usr/local/omc - binDir: /usr/local/omc/bin - backup: /usr/local/omc/backup - upload: /usr/local/omc/upload - frontUpload: /usr/local/omc/htdocs/front/upload - frontTraceDir: /usr/local/omc/htdocs/front/trace - software: /usr/local/omc/software - license: /usr/local/omc/license - gtpUri: gtp:192.168.2.119:32152 - checkContentType: false - testMode: false - rbacMode: true - runDir: /usr/local/omc/run - cmdTimeout: 120 - -# Alarm module setting -# Forward interface: -# TLS Skip verify: true/false -# email/sms -# smProxy: sms(Short Message Service)/smsc(SMS Centre) -# dataCoding: 0:GSM7BIT, 1:ASCII, 2:BINARY8BIT1, 3:LATIN1, -# 4:BINARY8BIT2, 6:CYRILLIC, 7:HEBREW, 8:UCS2 -alarm: - alarmEmailForward: - enable: false - emailList: "" - title: "Alarm from OMC" - smtp: mail.smtp.com - port: 25 - user: smtpext@smtp.com - password: "1000smtp@omc!" - tlsSkipVerify: true - alarmSMSForward: - enable: false - mobileList: "" - smscAddr: "192.168.13.114:2775" - systemID: "omc" - password: "omc123" - systemType: "UTRAN" - dataCoding: 0 - serviceNumber: "OMC" - sms: - apiURL: http://smsc.xxx.com/ - accessKeyID: xxxx - accessKeySecret: xxxx - signName: xxx SMSC - templateCode: 1000 - smProxy: smsc - -# User authorized information -# crypt: mysql/md5/bcrypt -# token: true/false to check accessToken -# expires for session, unit: second -# Support single/multiple session of user -# -auth: - crypt: bcrypt - token: true - expires: 1800 - session: multiple - publicKey: /usr/local/omc/etc/certs/omc - privateKey: /usr/local/omc/etc/certs/omc - -# Parameter for limit number -# rmuid_maxnum: the max number of rmUID, default: 50 -# alarmid_maxnum: the max number of AlarmID, default: 50 -# pmid_maxnum: the max number of pmID, default: 50 -# subid_maxnum: the max number of subscription ID, default: 20 -# uri_maxlen: the max length of uri, default: 8192 -# rmuid_regexp: regexp pattern of rmUID -params: - rmuidmaxnum: 50 - alarmidmaxnum: 50 - pmidmaxnum: 50 - subidmaxnum: 20 - urimaxlen: 2100000 - rmuidregexp: "[0-9]{4}[A-Z]{2}[A-Z]{2}[0-9A-Z]{1}[0-9A-Z]{3}[0-9A-Z]{1,16}" - -testConfig: - enabled: false - file: /usr/local/omc/etc/testconfig.yaml +# notification only alarm use +notification: + email: + enable: false # email enable + list: "" # toEmail,email,email + title: "Alarm from OMC" # email title + smtp: "mail.smtp.com" # email smtp + port: 25 # email port + user: "smtpext@smtp.com" # email user + password: "1000smtp@omc!" # email password + smsc: + enable: false # smsc enable + list: "" # toMobile,mobile,mobile + addr: "192.168.13.114:2775" # smsc addr + systemid: "omc" # smsc system id + systemtype: "UTRAN" # smsc system type + password: "omc123" # smsc password + coding: 0 # smsc codingMap 0:GSM7BIT, 1:ASCII, 2:BINARY8BIT1, 3:LATIN1, 4:BINARY8BIT2, 6:CYRILLIC, 7:HEBREW, 8:UCS2 + servicenumber: "OMC" # smsc service number diff --git a/src/config/config.default.yaml b/src/config/config.default.yaml index c98c4678..41ef001b 100644 --- a/src/config/config.default.yaml +++ b/src/config/config.default.yaml @@ -7,6 +7,29 @@ serverLoginAuth: true # 接口加密,默认关闭 serverCryptoApi: false +# 路由服务配置 +# 服务监听 ipv4/v6 端口,支持多路由 +routeServer: + - addr: "0.0.0.0:33030" # 路由 http 端口 + schema: "http" + - addr: "0.0.0.0:33443" # 路由 https 端口 + schema: "https" + certFile: "/usr/local/etc/omc/certs/www.omc.net.crt" + keyFile: "/usr/local/etc/omc/certs/www.omc.net.key" + +# Web 服务配置 +# 如果使用 nginx 接管,可以禁用 +webServer: + enabled: true # Web 服务启用,默认 false + rootDir: /usr/local/etc/omc/web + listen: + - addr: "0.0.0.0:80" # Web http 端口 + schema: "http" + - addr: "0.0.0.0:443" # Web https 端口 + schema: "https" + certFile: "/usr/local/etc/omc/certs/www.omc.net.crt" + keyFile: "/usr/local/etc/omc/certs/www.omc.net.key" + # 日志 logger: fileDir: "/var/log" @@ -158,7 +181,7 @@ database: # 内置轻量级数据库 lite: type: "sqlite" - database: "" + database: "" logging: false # 多个数据源时可以用这个指定默认的数据源 defaultDataSourceName: "std" diff --git a/src/config/config.local.yaml b/src/config/config.local.yaml index 250cdc6f..19e30744 100644 --- a/src/config/config.local.yaml +++ b/src/config/config.local.yaml @@ -1,49 +1,45 @@ -# 日志 +# log logger: - fileDir: "/var/log" - fileName: "omc.log" - level: 0 # 日志记录的等级 0:silent<1:info<2:warn<3:error - maxDay: 7 # 日志会保留 180 天 - maxSize: 10 # 调整按 10MB 大小的切割 + fileDir: "/var/log" # Log File Dir + fileName: "omc.log" # Log File Name + level: 0 # Log Level of 0:silent<1:info<2:warn<3:error + maxDay: 7 # Log retention Days + maxSize: 10 # Log File cutting by size -# 静态文件配置, 相对项目根路径或填绝对路径 +# static file resource access staticFile: - # 默认资源,dir目录需要预先创建 default: - prefix: "/static" - dir: "/usr/local/omc/static" - # 文件上传资源目录映射,与项目目录同级 + prefix: "/static" # Static File Prefix + dir: "/usr/local/omc/static" # Static File Dir upload: - prefix: "/upload" - dir: "/usr/local/omc/upload" + prefix: "/upload" # Upload File Prefix + dir: "/usr/local/omc/upload" # Upload File Dir -# DB 数据源 +# data source database: dataSource: - # 默认数据库实例 + # std: standard std: type: "mysql" - host: "127.0.0.1" - port: 33066 - username: "root" - password: "1000omc@kp!" - database: "omc_db" - logging: true - # 内置轻量级数据库 + host: "127.0.0.1" # mysql host + port: 33066 # mysql port + username: "root" # mysql username + password: "1000omc@kp!" # mysql password + database: "omc_db" # mysql database + # lite: lite lite: type: "sqlite" - database: "/usr/local/etc/omc/database/omc_db.sqlite" - logging: true - # 多个数据源时可以用这个指定默认的数据源 + database: "/usr/local/etc/omc/database/omc_db.sqlite" # sqlite database + # default data source name defaultDataSourceName: "std" -# Redis 缓存数据 +# redis cached data redis: dataSource: default: - port: 6379 # Redis port - host: "127.0.0.1" # Redis host - password: "helloearth" + port: 6379 # redis port + host: "127.0.0.1" # redis host + password: "helloearth" # redis password db: 10 # Redis db_num - # 多个数据源时可以用这个指定默认的数据源 + # default data source name defaultDataSourceName: "default" diff --git a/src/config/config.prod.yaml b/src/config/config.prod.yaml index bdf5cfd6..6e380cbf 100644 --- a/src/config/config.prod.yaml +++ b/src/config/config.prod.yaml @@ -1,30 +1,28 @@ -# DB 数据源 +# data source database: dataSource: - # 默认数据库实例 + # std: standard std: type: "mysql" - host: "127.0.0.1" - port: 33066 - username: "root" - password: "1000omc@kp!" - database: "omc_db" - logging: false - # 内置轻量级数据库 + host: "127.0.0.1" # mysql host + port: 33066 # mysql port + username: "root" # mysql username + password: "1000omc@kp!" # mysql password + database: "omc_db" # mysql database + # lite: lite lite: type: "sqlite" - database: "/usr/local/etc/omc/database/omc_db.sqlite" - logging: false - # 多个数据源时可以用这个指定默认的数据源 + database: "/usr/local/etc/omc/database/omc_db.sqlite" # sqlite database + # default data source name defaultDataSourceName: "std" -# Redis 缓存数据 +# redis cached data redis: dataSource: default: - port: 6379 # Redis port - host: "127.0.0.1" # Redis host - password: "helloearth" + port: 6379 # redis port + host: "127.0.0.1" # redis host + password: "helloearth" # redis password db: 10 # Redis db_num - # 多个数据源时可以用这个指定默认的数据源 + # default data source name defaultDataSourceName: "default" diff --git a/src/framework/config/config.go b/src/framework/config/config.go index 764333d4..c4e8fc0f 100644 --- a/src/framework/config/config.go +++ b/src/framework/config/config.go @@ -10,8 +10,6 @@ import ( "github.com/spf13/pflag" "github.com/spf13/viper" - - libConfig "be.ems/lib/config" ) var ( @@ -21,11 +19,10 @@ var ( ) // 程序配置 -var conf *viper.Viper +var conf *viper.Viper = viper.New() // 初始化程序配置 func InitConfig(configDir *embed.FS) { - conf = viper.New() initFlag() initViper(configDir) } @@ -97,16 +94,14 @@ func initViper(configDir *embed.FS) { // 外部文件配置 externalConfig := conf.GetString("config") if externalConfig != "" { - // readExternalConfig(externalConfig) - // 处理旧配置,存在相同的配置项处理 - configInMerge(externalConfig) + readExternalConfig(externalConfig) } // 记录程序开始运行的时间点 conf.Set("runTime", time.Now()) } -// readExternalConfig 读取外部文件配置(放弃旧的配置序列化时候才用) +// readExternalConfig 读取外部文件配置 func readExternalConfig(configPaht string) { f, err := os.Open(configPaht) if err != nil { @@ -121,38 +116,6 @@ func readExternalConfig(configPaht string) { } } -// 配置文件读取进行内部参数合并 -func configInMerge(configFile string) { - // 指定配置文件读取序列化 - libConfig.ReadConfig(configFile) - uriPrefix := libConfig.GetYamlConfig().OMC.UriPrefix - if uriPrefix != "" { - libConfig.UriPrefix = uriPrefix - } - if libConfig.GetYamlConfig().TestConfig.Enabled { - libConfig.ReadTestConfigYaml(libConfig.GetYamlConfig().TestConfig.File) - } - - // 配置文件读取 - var v = viper.New() - // 设置配置文件路径 - v.SetConfigFile(configFile) - v.SetConfigType("yaml") - // 读取配置文件 - if err := v.ReadInConfig(); err != nil { - fmt.Printf("failure to read configuration file: %v \n", err) - return - } - // 合并外层lib和features使用配置 - for key, value := range v.AllSettings() { - // 跳过配置 - if key == "testconfig" || key == "logger" { - continue - } - conf.Set(key, value) - } -} - // Env 获取运行服务环境 // local prod func Env() string {