Help us shape the future of Go! Take the 2026 Go Developer Survey

config

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 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"`
}

type Cache

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

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"`
	Log    LogConfig `mapstructure:"log"`
}

func GetConfig added in v1.0.1

func GetConfig() *Config

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

type DB

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

type Jwt

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

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

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

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

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

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

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

Jump to

Keyboard shortcuts

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