config

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBool added in v1.0.13

func GetBool(key string) bool

GetBool 获取指定 key 的布尔配置值,支持自定义配置

func GetDuration added in v1.0.13

func GetDuration(key string) time.Duration

GetDuration 获取指定 key 的 Duration 配置值,支持自定义配置

func GetFloat64 added in v1.0.13

func GetFloat64(key string) float64

GetFloat64 获取指定 key 的浮点数配置值,支持自定义配置

func GetInt added in v1.0.13

func GetInt(key string) int

GetInt 获取指定 key 的整数配置值,支持自定义配置

func GetString added in v1.0.13

func GetString(key string) string

GetString 获取指定 key 的字符串配置值,支持自定义配置 key 支持点号分隔的路径,如 "myapp.timeout"

func GetStringMap added in v1.0.13

func GetStringMap(key string) map[string]any

GetStringMap 获取指定 key 的 map 配置值,支持自定义配置

func GetStringMapString added in v1.0.13

func GetStringMapString(key string) map[string]string

GetStringMapString 获取指定 key 的 map[string]string 配置值,支持自定义配置

func GetStringSlice added in v1.0.13

func GetStringSlice(key string) []string

GetStringSlice 获取指定 key 的字符串切片配置值,支持自定义配置

func GetViper added in v1.0.13

func GetViper() *viper.Viper

GetViper 返回 viper 实例,用于自定义配置查询

func Init

func Init() *viper.Viper

Init 函数负责初始化配置 它会解析命令行参数,读取配置文件,并反序列化到 Config 结构体中

func InitConfig added in v1.0.1

func InitConfig()

func IsSet added in v1.0.13

func IsSet(key string) bool

IsSet 检查指定 key 是否已设置,支持自定义配置

func SetViper added in v1.0.13

func SetViper(viperInstance *viper.Viper)

SetViper 允许外部设置 viper 实例(主要用于测试)

func Unmarshal added in v1.0.13

func Unmarshal(rawVal any) error

Unmarshal 将整个配置反序列化到用户自定义结构体

func UnmarshalKey added in v1.0.13

func UnmarshalKey(key string, rawVal any) error

UnmarshalKey 将指定 key 的配置反序列化到用户自定义结构体 例如: config.UnmarshalKey("myapp", &myConfig)

Types

type Aliyun added in v1.0.1

type Aliyun struct {
	AccessKeyID     *string `mapstructure:"accessKeyId"`
	AccessKeySecret *string `mapstructure:"accessKeySecret"`
	Endpoint        *string `mapstructure:"endpoint"`
	Bucket          *string `mapstructure:"bucket"`
}

Aliyun 阿里云配置

func (*Aliyun) GetAccessKeyID added in v1.0.6

func (a *Aliyun) GetAccessKeyID() string

func (*Aliyun) GetAccessKeySecret added in v1.0.6

func (a *Aliyun) GetAccessKeySecret() string

func (*Aliyun) GetBucket added in v1.0.6

func (a *Aliyun) GetBucket() string

func (*Aliyun) GetEndpoint added in v1.0.6

func (a *Aliyun) GetEndpoint() string

type Auth

type Auth struct {
	IsAuth     *bool    `mapstructure:"isAuth"`
	Ignores    []string `mapstructure:"ignores"`
	NeedLogins []string `mapstructure:"needLogins"`
}

func (*Auth) GetIgnores added in v1.0.3

func (a *Auth) GetIgnores() []string

func (*Auth) GetIsAuth added in v1.0.3

func (a *Auth) GetIsAuth() bool

type Cache

type Cache struct {
	NeedCache []string `mapstructure:"needCache"`
	Expire    *int64   `mapstructure:"expire"` //单位秒
}

func (*Cache) GetExpire added in v1.0.3

func (c *Cache) GetExpire() int64

func (*Cache) GetNeedCache added in v1.0.3

func (c *Cache) GetNeedCache() []string

type Config

type Config struct {
	Pay           *Pay           `mapstructure:"pay"`
	Server        *Server        `mapstructure:"server"`
	Cache         *Cache         `mapstructure:"cache"`
	Upload        *Upload        `mapstructure:"upload"`
	Qiniu         *Qiniu         `mapstructure:"qiniu"`
	Aliyun        *Aliyun        `mapstructure:"aliyun"`
	DB            *DB            `mapstructure:"db"`
	Auth          *Auth          `mapstructure:"auth"`
	Wx            *Wx            `mapstructure:"wx"`
	Jwt           *Jwt           `mapstructure:"jwt"`
	Email         *Email         `mapstructure:"email"`
	Log           *LogConfig     `mapstructure:"log"`
	Elasticsearch *Elasticsearch `mapstructure:"elasticsearch"`
	Milvus        *Milvus        `mapstructure:"milvus"`
	Skill         *Skill         `mapstructure:"skill"`
}

func GetConfig added in v1.0.1

func GetConfig() *Config

GetConfig 返回已加载的配置单例 在调用此函数前,必须先调用 Init()

func (*Config) GetAliyun added in v1.0.6

func (c *Config) GetAliyun() *Aliyun

func (*Config) GetJwt added in v1.0.3

func (c *Config) GetJwt() *Jwt

type DB

type DB struct {
	Redis    *Redis    `mapstructure:"redis"`
	Mysql    *Mysql    `mapstructure:"mysql"`
	Postgres *Postgres `mapstructure:"postgres"`
}

type Elasticsearch added in v1.0.5

type Elasticsearch struct {
	Addresses []string `mapstructure:"addresses"`
	Username  *string  `mapstructure:"username"`
	Password  *string  `mapstructure:"password"`
	APIKey    *string  `mapstructure:"apiKey"`
}

Elasticsearch 配置结构体

func (*Elasticsearch) GetAPIKey added in v1.0.5

func (e *Elasticsearch) GetAPIKey() string

GetAPIKey 获取 ES API Key

func (*Elasticsearch) GetAddresses added in v1.0.5

func (e *Elasticsearch) GetAddresses() []string

GetAddresses 获取 ES 地址列表

func (*Elasticsearch) GetPassword added in v1.0.5

func (e *Elasticsearch) GetPassword() string

GetPassword 获取 ES 密码

func (*Elasticsearch) GetUsername added in v1.0.5

func (e *Elasticsearch) GetUsername() string

GetUsername 获取 ES 用户名

type Email added in v1.0.2

type Email struct {
	Host     *string `mapstructure:"host"`
	Port     *int    `mapstructure:"port"`
	Username *string `mapstructure:"username"`
	Password *string `mapstructure:"password"`
	Identity *string `mapstructure:"identity"`
	From     *string `mapstructure:"from"`
	BaseURL  *string `mapstructure:"baseUrl"`
}

func (*Email) GetBaseURL added in v1.0.3

func (e *Email) GetBaseURL() string

func (*Email) GetFrom added in v1.0.3

func (e *Email) GetFrom() string

func (*Email) GetHost added in v1.0.3

func (e *Email) GetHost() string

func (*Email) GetIdentity added in v1.0.3

func (e *Email) GetIdentity() string

func (*Email) GetPassword added in v1.0.3

func (e *Email) GetPassword() string

func (*Email) GetPort added in v1.0.3

func (e *Email) GetPort() int

func (*Email) GetUsername added in v1.0.3

func (e *Email) GetUsername() string

type Jwt

type Jwt struct {
	Secret  *string        `mapstructure:"secret"`
	Expire  *time.Duration `mapstructure:"expire"`
	Refresh *time.Duration `mapstructure:"refresh"`
}

func (*Jwt) GetExpire added in v1.0.3

func (j *Jwt) GetExpire() time.Duration

func (*Jwt) GetRefresh added in v1.0.3

func (j *Jwt) GetRefresh() time.Duration

func (*Jwt) GetSecret added in v1.0.3

func (j *Jwt) GetSecret() string

type LogConfig added in v1.0.1

type LogConfig struct {
	Level      *string   `mapstructure:"level"`
	Format     *string   `mapstructure:"format"`
	AddSource  *bool     `mapstructure:"addSource"`
	Filename   *string   `mapstructure:"filename"`
	MaxSize    *int      `mapstructure:"maxSize"`
	MaxAge     *int      `mapstructure:"maxAge"`
	MaxBackups *int      `mapstructure:"maxBackups"`
	Output     io.Writer `mapstructure:"output"`
}

func (*LogConfig) GetAddSource added in v1.0.3

func (l *LogConfig) GetAddSource() bool

func (*LogConfig) GetFilename added in v1.0.3

func (l *LogConfig) GetFilename() string

func (*LogConfig) GetFormat added in v1.0.3

func (l *LogConfig) GetFormat() string

func (*LogConfig) GetLevel added in v1.0.3

func (l *LogConfig) GetLevel() string

func (*LogConfig) GetMaxAge added in v1.0.3

func (l *LogConfig) GetMaxAge() int

func (*LogConfig) GetMaxBackups added in v1.0.3

func (l *LogConfig) GetMaxBackups() int

func (*LogConfig) GetMaxSize added in v1.0.3

func (l *LogConfig) GetMaxSize() int

type Milvus added in v1.0.5

type Milvus struct {
	Address  *string `mapstructure:"address"`
	DBName   *string `mapstructure:"dbName"`
	Username *string `mapstructure:"username"`
	Password *string `mapstructure:"password"`
}

Milvus 配置结构体

func (*Milvus) GetAddress added in v1.0.5

func (m *Milvus) GetAddress() string

GetAddress 获取 Milvus 地址

func (*Milvus) GetDBName added in v1.0.5

func (m *Milvus) GetDBName() string

GetDBName 获取 Milvus 数据库名称

func (*Milvus) GetPassword added in v1.0.5

func (m *Milvus) GetPassword() string

GetPassword 获取 Milvus 密码

func (*Milvus) GetUsername added in v1.0.5

func (m *Milvus) GetUsername() string

GetUsername 获取 Milvus 用户名

type Mysql

type Mysql struct {
	Host         *string        `mapstructure:"host"`
	Port         *int           `mapstructure:"port"`
	User         *string        `mapstructure:"user"`
	Password     *string        `mapstructure:"password"`
	Database     *string        `mapstructure:"database"`
	MaxIdleConns *int           `mapstructure:"maxIdleConns"`
	PingTimeout  *time.Duration `mapstructure:"pingTimeout"`
	MaxOpenConns *int           `mapstructure:"maxOpenConns"`
	Log          *MysqlLog      `mapstructure:"log"`
}

func (*Mysql) GetDatabase added in v1.0.3

func (m *Mysql) GetDatabase() string

func (*Mysql) GetHost added in v1.0.3

func (m *Mysql) GetHost() string

func (*Mysql) GetLog added in v1.0.9

func (m *Mysql) GetLog() *MysqlLog

func (*Mysql) GetMaxIdleConns added in v1.0.3

func (m *Mysql) GetMaxIdleConns() int

func (*Mysql) GetMaxOpenConns added in v1.0.3

func (m *Mysql) GetMaxOpenConns() int

func (*Mysql) GetPassword added in v1.0.3

func (m *Mysql) GetPassword() string

func (*Mysql) GetPingTimeout added in v1.0.3

func (m *Mysql) GetPingTimeout() time.Duration

func (*Mysql) GetPort added in v1.0.3

func (m *Mysql) GetPort() int

func (*Mysql) GetUser added in v1.0.3

func (m *Mysql) GetUser() string

type MysqlLog added in v1.0.9

type MysqlLog struct {
	SlowThreshold             *time.Duration `mapstructure:"slowThreshold"`
	LogLevel                  *string        `mapstructure:"level"`
	IgnoreRecordNotFoundError *bool          `mapstructure:"ignoreRecordNotFoundError"`
	ParameterizedQueries      *bool          `mapstructure:"parameterizedQueries"`
	Colorful                  *bool          `mapstructure:"colorful"`
}

func (*MysqlLog) GetColorful added in v1.0.9

func (ml *MysqlLog) GetColorful() bool

func (*MysqlLog) GetIgnoreRecordNotFoundError added in v1.0.9

func (ml *MysqlLog) GetIgnoreRecordNotFoundError() bool

func (*MysqlLog) GetLogLevel added in v1.0.9

func (ml *MysqlLog) GetLogLevel() logger.LogLevel

func (*MysqlLog) GetParameterizedQueries added in v1.0.9

func (ml *MysqlLog) GetParameterizedQueries() bool

func (*MysqlLog) GetSlowThreshold added in v1.0.9

func (ml *MysqlLog) GetSlowThreshold() time.Duration

type Pay

type Pay struct {
	WxPay *WxPay `mapstructure:"wxPay"`
}

type Postgres added in v1.0.1

type Postgres struct {
	Host         *string        `mapstructure:"host"`
	Port         *int           `mapstructure:"port"`
	User         *string        `mapstructure:"user"`
	Password     *string        `mapstructure:"password"`
	Database     *string        `mapstructure:"database"`
	SSLMode      *string        `mapstructure:"sslmode"`
	MaxIdleConns *int           `mapstructure:"maxIdleConns"`
	PingTimeout  *time.Duration `mapstructure:"pingTimeout"`
	MaxOpenConns *int           `mapstructure:"maxOpenConns"`
	Log          *PostgresLog   `mapstructure:"log"`
}

func (*Postgres) GetDatabase added in v1.0.3

func (p *Postgres) GetDatabase() string

func (*Postgres) GetHost added in v1.0.3

func (p *Postgres) GetHost() string

func (*Postgres) GetLog added in v1.0.9

func (p *Postgres) GetLog() *PostgresLog

func (*Postgres) GetMaxIdleConns added in v1.0.3

func (p *Postgres) GetMaxIdleConns() int

func (*Postgres) GetMaxOpenConns added in v1.0.3

func (p *Postgres) GetMaxOpenConns() int

func (*Postgres) GetPassword added in v1.0.3

func (p *Postgres) GetPassword() string

func (*Postgres) GetPingTimeout added in v1.0.3

func (p *Postgres) GetPingTimeout() time.Duration

func (*Postgres) GetPort added in v1.0.3

func (p *Postgres) GetPort() int

func (*Postgres) GetSSLMode added in v1.0.3

func (p *Postgres) GetSSLMode() string

func (*Postgres) GetUser added in v1.0.3

func (p *Postgres) GetUser() string

type PostgresLog added in v1.0.9

type PostgresLog struct {
	SlowThreshold             *time.Duration `mapstructure:"slowThreshold"`
	LogLevel                  *string        `mapstructure:"level"`
	IgnoreRecordNotFoundError *bool          `mapstructure:"ignoreRecordNotFoundError"`
	ParameterizedQueries      *bool          `mapstructure:"parameterizedQueries"`
	Colorful                  *bool          `mapstructure:"colorful"`
}

func (*PostgresLog) GetColorful added in v1.0.9

func (pl *PostgresLog) GetColorful() bool

func (*PostgresLog) GetIgnoreRecordNotFoundError added in v1.0.9

func (pl *PostgresLog) GetIgnoreRecordNotFoundError() bool

func (*PostgresLog) GetLogLevel added in v1.0.9

func (pl *PostgresLog) GetLogLevel() logger.LogLevel

func (*PostgresLog) GetParameterizedQueries added in v1.0.9

func (pl *PostgresLog) GetParameterizedQueries() bool

func (*PostgresLog) GetSlowThreshold added in v1.0.9

func (pl *PostgresLog) GetSlowThreshold() time.Duration

type Qiniu

type Qiniu struct {
	Bucket    *string `mapstructure:"bucket"`
	AccessKey *string `mapstructure:"accessKey"`
	SecretKey *string `mapstructure:"secretKey"`
	Region    *string `mapstructure:"region"`
}

type Redis

type Redis struct {
	Addr         *string `mapstructure:"addr"`
	Password     *string `mapstructure:"password"`
	DB           *int    `mapstructure:"db"`
	PoolSize     *int    `mapstructure:"poolSize"`
	IdleTimeout  *int    `mapstructure:"idleTimeout"`
	MaxOpenConns *int    `mapstructure:"maxOpenConns"`
	MaxIdleConns *int    `mapstructure:"maxIdleConns"`
}

func (*Redis) GetAddr added in v1.0.3

func (r *Redis) GetAddr() string

func (*Redis) GetDB added in v1.0.3

func (r *Redis) GetDB() int

func (*Redis) GetMaxIdleConns added in v1.0.3

func (r *Redis) GetMaxIdleConns() int

func (*Redis) GetMaxOpenConns added in v1.0.3

func (r *Redis) GetMaxOpenConns() int

func (*Redis) GetPassword added in v1.0.3

func (r *Redis) GetPassword() string

func (*Redis) GetPoolSize added in v1.0.3

func (r *Redis) GetPoolSize() int

type Server

type Server struct {
	Port         *int           `mapstructure:"port"`
	Cros         []string       `mapstructure:"cros"`
	AllowOrigins []string       `mapstructure:"allowOrigins"`
	Mode         *string        `mapstructure:"mode"`
	Name         *string        `mapstructure:"name"`
	Version      *string        `mapstructure:"version"`
	Host         *string        `mapstructure:"host"`
	ReadTimeout  *time.Duration `mapstructure:"readTimeout"`
	WriteTimeout *time.Duration `mapstructure:"writeTimeout"`
}

func (*Server) GetCros added in v1.0.3

func (s *Server) GetCros() []string

func (*Server) GetHost added in v1.0.3

func (s *Server) GetHost() string

func (*Server) GetMode added in v1.0.3

func (s *Server) GetMode() string

func (*Server) GetPort added in v1.0.3

func (s *Server) GetPort() int

func (*Server) GetReadTimeout added in v1.0.3

func (s *Server) GetReadTimeout() time.Duration

func (*Server) GetWriteTimeout added in v1.0.3

func (s *Server) GetWriteTimeout() time.Duration

type Skill added in v1.0.13

type Skill struct {
	BaseDir *string `mapstructure:"baseDir"`
}

func (*Skill) GetBaseDir added in v1.0.13

func (s *Skill) GetBaseDir() string

type Upload

type Upload struct {
	Prefix *string `mapstructure:"prefix"`
}

type Wx

type Wx struct {
	AppId  *string `mapstructure:"appId"`
	Secret *string `mapstructure:"secret"`
	Token  *string `mapstructure:"token"`
	AesKey *string `mapstructure:"aesKey"`
}

type WxPay

type WxPay struct {
	AppId       *string `mapstructure:"appId"`
	MchId       *string `mapstructure:"mchId"`       //商户证书的证书序列号
	MchSerialNo *string `mapstructure:"mchSerialNo"` //商户证书的证书序列号
	ApiV3Key    *string `mapstructure:"apiV3Key"`    //apiV3Key,商户平台获取
	PrivateKey  *string `mapstructure:"privateKey"`  //私钥 apiclient_key.pem 读取后的内容
	AppSecret   *string `mapstructure:"appSecret"`
	NotifyUrl   *string `mapstructure:"notifyUrl"`
	MchCertPath *string `mapstructure:"mchCertPath"`
	MchKeyPath  *string `mapstructure:"mchKeyPath"`
}

func (*WxPay) GetAppId added in v1.0.3

func (w *WxPay) GetAppId() string

func (*WxPay) GetMchId added in v1.0.3

func (w *WxPay) GetMchId() string

func (*WxPay) GetNotifyUrl added in v1.0.3

func (w *WxPay) GetNotifyUrl() string

Jump to

Keyboard shortcuts

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