Documentation ¶
Index ¶
- Constants
- Variables
- func ReadConfig(cfgPath string) (*viper.Viper, error)
- type Config
- type DataBaseConfig
- type DataBaseConfigGroup
- type GormDBGroup
- type I18nConfig
- type JwtConfig
- type LogFileConfig
- type MailConfig
- type MysqlConfig
- type RedisConfig
- type ServerConfig
- type ZapConfig
- func (z *ZapConfig) BuildOptions(levelEnabler zapcore.LevelEnabler) (options []zap.Option)
- func (z *ZapConfig) ZapConsoleEncoder() zapcore.Encoder
- func (z *ZapConfig) ZapConsoleWriterSyncer() zapcore.WriteSyncer
- func (z *ZapConfig) ZapFileEncoder() zapcore.Encoder
- func (z *ZapConfig) ZapFileWriterSyncer() zapcore.WriteSyncer
- func (z *ZapConfig) ZapLevelEnabler() zapcore.LevelEnabler
Constants ¶
const ( Tes = "test" Dev = "dev" Pro = "product" )
const ( DebugLevel = "debug" InfoLevel = "info" ErrorLevel = "error" PanicLevel = "panic" FatalLevel = "fatal" WriteFile = "file" WriteConsole = "console" WriteBoth = "both" )
Variables ¶
var ( Mysql = "mysql" PostgreSql = "postgreSql" MysqlLoadConfigErr = errors.New("mysql load config failed") RedisLoadConfigErr = errors.New("redis load config failed") )
Functions ¶
Types ¶
type Config ¶
type Config struct { DataBaseConfig *DataBaseConfigGroup `mapstructure:"database"` RedisConfig *RedisConfig `mapstructure:"redis"` JwtConfig *JwtConfig `mapstructure:"jwt"` ServerConfig *ServerConfig `mapstructure:"server"` ZapConfig *ZapConfig `mapstructure:"zap"` I18nConfig *I18nConfig `mapstructure:"i18n"` MailConfig *MailConfig `mapstructure:"mail"` }
Config @Date: 2023-01-09 13:48:50 @Description: 全局配置结构体,映射了整个配置文件
type DataBaseConfig ¶
type DataBaseConfig struct { Enable bool `yaml:"enable"` Type string `yaml:"type"` Ip string `yaml:"ip"` Port string `yaml:"port"` DbName string `yaml:"dbName"` Config string `yaml:"config"` Username string `yaml:"username"` Password string `yaml:"password"` MaxIldeCons int `yaml:"maxIldeCons"` MaxOpenCons int `yaml:"maxOpenCons"` }
DataBaseConfig @Date: 2023-01-08 19:10:05 @Description: Mysql配置
type DataBaseConfigGroup ¶
type DataBaseConfigGroup = map[string]*DataBaseConfig
type GormDBGroup ¶
type I18nConfig ¶
I18nConfig @Date 2023-01-12 15:15:54 @Description: i18n配置文件结构体
type JwtConfig ¶
type JwtConfig struct { AcSign string `mapstructure:"acSign"` ReSign string `mapstructure:"reSign"` AcExp int64 `mapstructure:"acExp"` AcAlo int64 `mapstructure:"acAlo"` ReExp int64 `mapstructure:"reExp"` Issuer string `mapstructure:"issuer"` }
func (*JwtConfig) AcAllowExpTime ¶
AcAllowExpTime @Date 2023-01-20 22:51:33 @Return time.Duration @Method @Description: 允许过期时间
type LogFileConfig ¶
type LogFileConfig struct { MaxSize int `yaml:"maxSize" mapstructure:"maxSize"` BackUps int `yaml:"backups" mapstructure:"backups"` Compress bool `yaml:"compress" mapstructure:"compress"` Output []string `yaml:"output" mapstructure:"output"` }
LogFileConfig @Date: 2023-01-09 16:38:45 @Description: 日志文件配置结构体
type MailConfig ¶
type MailConfig struct { Host string `mapstructure:"host"` Port int `mapstructure:"port"` Username string `mapstructure:"username"` Password string `mapstructure:"password"` // Expire // @Date 2023-02-08 17:20:50 // @Description: 验证码过期时间 Expire int `mapstructure:"expire"` // Limit // @Date 2023-02-08 17:20:56 // @Description: 邮件重复发送限制 Limit int `mapstructure:"limit"` }
MailConfig @Date 2023-02-08 15:32:32 @Description: 邮件客户端连接配置
type MysqlConfig ¶
type MysqlConfig struct {
C *DataBaseConfig
}
func (MysqlConfig) Dsn ¶
func (m MysqlConfig) Dsn() string
type RedisConfig ¶
RedisConfig @Date: 2023-01-08 19:10:33 @Description: Redis配置
func (RedisConfig) RedisOptions ¶
func (r RedisConfig) RedisOptions() *redis.Options
type ServerConfig ¶
type ServerConfig struct { // Port // @Date 2023-01-11 16:54:44 // @Description: 服务端口 Port string `yaml:"port"` // Mode // @Date 2023-01-11 16:54:54 // @Description: 运行模式 debug||test||release Mode string `yaml:"mode"` // Limit // @Date 2023-02-10 20:36:19 // @Description: QPS最大值 Limit int64 `yaml:"limit"` // Rate // @Date 2023-02-10 20:35:38 // @Description: 令牌每秒放入令牌的比例 Rate float64 `yaml:"rate"` // Cache // @Date 2023-02-10 21:25:38 // @Description: 缓存时间 Cache int64 `yaml:"cache"` // ReadTimeout // @Date 2023-01-11 16:55:10 // @Description: http请求读取超时时间 ReadTimeout time.Duration `yaml:"readTimeout"` // WriteTimeout // @Date 2023-01-11 16:55:20 // @Description: http写入响应的超时时间 WriteTimeout time.Duration `yaml:"writeTimeout"` // IdleTimeout // @Date 2023-01-11 16:55:48 // @Description: 连接复用的超时时间 IdleTimeout time.Duration `yaml:"idleTimeout"` // ReadHeaderTimeout // @Date 2023-01-11 16:56:07 // @Description: 请求头读取超时时间 ReadHeaderTimeout time.Duration `yaml:"readHeaderTimeout"` // MultipartMemory // @Date 2023-01-11 16:56:24 // @Description: Multipart表单的大小限制 MultipartMemory int64 `yaml:"multipartMemory"` // MaxHeaderBytes // @Date 2023-01-11 16:57:04 // @Description: 最大请求大小 MaxHeaderBytes int `yaml:"maxHeaderBytes"` // WorkDir // @Date 2023-01-23 22:05:37 // @Description: 服务器的工作目录 WorkDir string // StaticDir // @Date 2023-01-23 22:08:32 // @Description: 静态文件的存放路径 StaticDir string `yaml:"static" mapstructure:"static"` }
ServerConfig @Date 2023-01-11 16:54:02 @Description: 应用配置
func (*ServerConfig) Addr ¶
func (s *ServerConfig) Addr() string
func (*ServerConfig) AddrHost ¶
func (s *ServerConfig) AddrHost(host string) string
func (*ServerConfig) IdleTimeOut ¶
func (s *ServerConfig) IdleTimeOut() time.Duration
IdleTimeOut @Date 2023-01-11 16:19:19 @Return time.Duration @Description: Keep alive Http连接复用的超时时间
func (*ServerConfig) ReadHeaderTimeOut ¶
func (s *ServerConfig) ReadHeaderTimeOut() time.Duration
ReadHeaderTimeOut @Date 2023-01-11 16:19:45 @Return time.Duration @Description: 读取Http请求头的超时时间
func (*ServerConfig) ReadTimeOut ¶
func (s *ServerConfig) ReadTimeOut() time.Duration
ReadTimeOut @Date 2023-01-11 16:18:53 @Return time.Duration @Description: 读取Http请求的超时时间
func (*ServerConfig) WriteTimeOut ¶
func (s *ServerConfig) WriteTimeOut() time.Duration
WriteTimeOut @Date 2023-01-11 16:19:05 @Return time.Duration @Description: 写入Http响应的超时时间
type ZapConfig ¶
type ZapConfig struct { Prefix string `yaml:"prefix" mapstructure:""prefix` TimeFormat string `yaml:"timeFormat" mapstructure:"timeFormat"` Level string `yaml:"level" mapstructure:"level"` Caller bool `yaml:"caller" mapstructure:"caller"` StackTrace bool `yaml:"stackTrace" mapstructure:"stackTrace"` Writer string `yaml:"writer" mapstructure:"writer"` Encode string `yaml:"encode" mapstructure:"encode"` LogFile *LogFileConfig `yaml:"logFile" mapstructure:"logFile"` }
ZapConfig @Date: 2023-01-09 16:37:05 @Description: zap日志配置结构体
func (*ZapConfig) BuildOptions ¶
func (z *ZapConfig) BuildOptions(levelEnabler zapcore.LevelEnabler) (options []zap.Option)
BuildOptions @Date: 2023-01-09 20:46:39 @Description: 构建Options @Receiver: z *ZapConfig @Param: levelEnabler zapcore.LevelEnabler @Return: options []zap.Option
func (*ZapConfig) ZapConsoleEncoder ¶
ZapConsoleEncoder @Date: 2023-01-09 15:34:21 @Description: 控制台编码器 @Return zapcore.Encoder
func (*ZapConfig) ZapConsoleWriterSyncer ¶
func (z *ZapConfig) ZapConsoleWriterSyncer() zapcore.WriteSyncer
ZapConsoleWriterSyncer @Date: 2023-01-09 20:51:02 @Description: 获取ConsoleWriterSyncer @Receiver: z *ZapConfig @Return: zapcore.WriteSyncer
func (*ZapConfig) ZapFileEncoder ¶
ZapFileEncoder @Date: 2023-01-09 20:59:35 @Description: 文件编码器 @Receiver: z *ZapConfig @Return: zapcore.Encoder
func (*ZapConfig) ZapFileWriterSyncer ¶
func (z *ZapConfig) ZapFileWriterSyncer() zapcore.WriteSyncer
ZapFileWriterSyncer @Date: 2023-01-09 20:52:02 @Description: 获取FileWriterSyncer @Receiver: z *ZapConfig @Return: zapcore.WriteSyncer
func (*ZapConfig) ZapLevelEnabler ¶
func (z *ZapConfig) ZapLevelEnabler() zapcore.LevelEnabler
ZapLevelEnabler @Date: 2023-01-09 16:03:23 @Description: @Param: cfg *config.ZapConfig @Return: zapcore.LevelEnabler