config

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init() *viper.Viper

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

func InitConfig added in v1.0.1

func InitConfig()

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 阿里云配置

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"`
	DB     *DB        `mapstructure:"db"`
	Auth   *Auth      `mapstructure:"auth"`
	Wx     *Wx        `mapstructure:"wx"`
	Jwt    *Jwt       `mapstructure:"jwt"`
	Email  *Email     `mapstructure:"email"`
	Log    *LogConfig `mapstructure:"log"`
}

func GetConfig added in v1.0.1

func GetConfig() *Config

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

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 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 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"`
}

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) 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 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"`
}

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) 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 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 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