Documentation
¶
Index ¶
- func GetConfig() *viper.Viper
- func InitConfig(conf string) error
- func IsInited() bool
- func ReadConfigToBool(title, key string) bool
- func ReadConfigToInt(title, key string) int
- func ReadConfigToString(title, key string) string
- func ReadConfigToTimeDuration(title, key string) time.Duration
- func SetViperConfig(conf *viper.Viper)
- type DBConfig
- type LogConfig
- type MongoDBConfig
- type MySQLConfig
- type SQLiteConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadConfigToTimeDuration ¶
读取配置文件中的时间值
Types ¶
type DBConfig ¶ added in v0.3.5
type DBConfig struct {
// 数据库类型 mysql mongodb sqlite
Type string `mapstructure:"db.type"`
// 日志配置
*LogConfig
// MySQL配置
*MySQLConfig
// MongoDB配置
*MongoDBConfig
// SQLite配置
*SQLiteConfig
}
DBConfig 是数据库总配置结构体
type LogConfig ¶ added in v0.3.5
type MongoDBConfig ¶ added in v0.3.5
type MongoDBConfig struct {
// 日志配置
*LogConfig
// mongodb连接的数据库
Database string `mapstructure:"mongodb.database"`
// 连接池大小
OptionPoolSize string `mapstructure:"mongodb.option_pool_size"`
// mongodb代理连接方法 必须是socks代理
Proxy string `mapstructure:"mongodb.proxy"`
// mongodb连接uri mongodb://[认证用户名]:[认证密码]@[连接地址]/[额外参数]
Uri string `mapstructure:"mongodb.uri"`
// w 写关注 默认majority
W string `mapstructure:"mongodb.w"`
// ReadMode 读模式 master nearest
ReadMode string `mapstructure:"mongodb.readmode"`
}
MongoDBConfig 是MongoDB数据库的配置结构体
func (*MongoDBConfig) Init ¶ added in v0.3.5
func (m *MongoDBConfig) Init()
Init 将MongoDB配置设置到config单例上
type MySQLConfig ¶ added in v0.3.5
type MySQLConfig struct {
// 日志配置
*LogConfig
// 自动创表
AutoCreateTable bool `mapstructure:"db.auto_create_table"`
// mysql连接数据库
Database string `mapstructure:"mysql.database"`
// 数据库编码
Charset string `mapstructure:"mysql.charset"`
// 连接最大生命时间
ConnMaxLifetime string `mapstructure:"mysql.conn_max_lifetime"`
// mysql连接主机
Host string `mapstructure:"mysql.host"`
// mysql连接端口
Port string `mapstructure:"mysql.port"`
// 最大空闲连接数
MaxIdleConns string `mapstructure:"mysql.max_idle_conns"`
// 最大连接数
MaxOpenConns string `mapstructure:"mysql.max_open_conns"`
// mysql认证用户
User string `mapstructure:"mysql.user"`
// mysql认证密码
Password string `mapstructure:"mysql.password"`
}
MySQLConfig 是MySQL数据库的配置结构体
type SQLiteConfig ¶ added in v0.3.5
type SQLiteConfig struct {
// 日志配置
*LogConfig
// 自动创表
AutoCreateTable bool `mapstructure:"db.auto_create_table"`
// 数据库路径
// 这里传入的是gorm的DSN 支持内存模式等其他特性 如:"file:testdatabase?mode=memory&cache=shared"
// 也可以传入数据库的存储路径
FilePath string `mapstructure:"sqlite.file_path"`
// 最大空闲连接数
MaxIdleConns string `mapstructure:"sqlite.max_idle_conns"`
// 最大连接数
MaxOpenConns string `mapstructure:"sqlite.max_open_conns"`
// 连接最大生命时间
ConnMaxLifetime string `mapstructure:"sqlite.conn_max_lifetime"`
}
SQLiteConfig 是SQLite数据库的配置结构体
func (*SQLiteConfig) Init ¶ added in v0.3.5
func (s *SQLiteConfig) Init()
Init 将SQLite配置设置到config单例上
Click to show internal directories.
Click to hide internal directories.