2 Star 0 Fork 0

码布什/go工具库

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
conf.go 2.05 KB
一键复制 编辑 原始数据 按行查看 历史
zhengqiuyun 提交于 2024-02-02 11:09 +08:00 . 图片访问路径构建封装
package conf
import (
"gitee.com/manoshi/go-util/util"
)
type Config struct {
ServerName string
Env string
HttpPort int
LogLevel string
LogColorful bool
LogResponseLength int
LogShowSql bool
AllowOrigin []string
Redis RedisConf
Elasticsearch EsConf
Mysql MysqlConf
}
func BaseConfig(conf Config) {
ServerName = conf.ServerName
Env = conf.Env
HttpPort = conf.HttpPort
if util.IsEmpty(&conf.LogLevel) {
LogLevel = "DEBUG"
} else {
LogLevel = conf.LogLevel
}
LogColorful = conf.LogColorful
LogResponseLength = conf.LogResponseLength
LogShowSql = conf.LogShowSql
AllowOrigin = conf.AllowOrigin
Es = conf.Elasticsearch
if Es.StoreDays == 0 {
Es.StoreDays = 180
}
Redis = conf.Redis
MySql = conf.Mysql
}
// Base conf
var ServerName string
var Env string
var HttpPort int
var AllowOrigin []string
// log conf
var LogLevel = "DEBUG"
var LogColorful = false
var LogResponseLength int
var LogShowSql = true
// Redis conf
type RedisConf struct {
RedisHost string
RedisPort int
RedisPwd string
RedisDb int
ReadTimeout int //取超时间 单位秒 默认值为3秒
WriteTimeout int // 写入超时时间 单位秒 默认与读超时时间一致
PoolSize int //最大连接数 默认cpu数*10
MinIdleConns int //最小空闲连接数
}
var Redis = RedisConf{}
// ES conf
type EsConf struct {
ServerHost string
ServerPort int
Sniff bool
LogType int //1、只记录用户操作,2、只记录非用户操作,3全记录
LogIndexNamePrefix string
UnLogUrls []string
CloseClearHisLog bool //是否关闭清理历史日志
ClearHisLogSpec string //清理历史日志的定时时间配置
StoreDays int //日志存放天数
CheckDuration int //检查间隔时间
}
var Es = EsConf{}
// Mysql conf
type MysqlConf struct {
Host string
Port int
User string
Password string
NameSpace string
MaxIdleConns int
MaxOpenConns int
}
var MySql = MysqlConf{}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/manoshi/go-util.git
git@gitee.com:manoshi/go-util.git
manoshi
go-util
go工具库
v0.2.19

搜索帮助