perf: 移除掉无用配置精简
This commit is contained in:
@@ -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 path>"
|
||||
database: "<database path>"
|
||||
logging: false
|
||||
# 多个数据源时可以用这个指定默认的数据源
|
||||
defaultDataSourceName: "std"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user