conf

package
v0.6.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetConfig added in v0.3.1

func GetConfig() *viper.Viper

获取当前配置实例

func InitConfig

func InitConfig(conf string) error

初始化配置文件

func IsInited added in v0.3.1

func IsInited() bool

检查配置是否已初始化

func ReadConfigToBool added in v0.3.6

func ReadConfigToBool(title, key string) bool

读取配置文件中的bool值

func ReadConfigToInt

func ReadConfigToInt(title, key string) int

读取配置文件中的int值

func ReadConfigToString

func ReadConfigToString(title, key string) string

读取配置文件中的string值

func ReadConfigToTimeDuration

func ReadConfigToTimeDuration(title, key string) time.Duration

读取配置文件中的时间值

func SetViperConfig added in v0.3.1

func SetViperConfig(conf *viper.Viper)

设置新的viper配置实例

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 是数据库总配置结构体

func (*DBConfig) Init added in v0.3.5

func (d *DBConfig) Init()

Init 将总配置设置到config单例上,并调用各数据库配置的Init方法

type LogConfig added in v0.3.5

type LogConfig struct {
	// 日志文件路径
	Log string `mapstructure:"db.log"`
	// 日志等级
	LogLevel types.LogLevel `mapstructure:"db.loglevel"`
}

func (*LogConfig) Init added in v0.3.5

func (l *LogConfig) Init()

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数据库的配置结构体

func (*MySQLConfig) Init added in v0.3.5

func (m *MySQLConfig) Init()

Init 将MySQL配置设置到config单例上

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单例上

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL