config

package
v0.0.0-...-a45afdf Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ServerConf  ServerConfig `ini:"server"  yaml:"server"` // 服务配置(对应INI的[server]节、YAML的server节点)
	MysqlConf   MysqlConfig  `ini:"mysql"   yaml:"mysql"`  // MySQL配置(对应INI的[mysql]节、YAML的mysql节点)
	RedisConf   RedisConfig  `ini:"redis"   yaml:"redis"`  // Redis配置(对应INI的[redis]节、YAML的redis节点)
	QiniuConfig QiniuConfig  `ini:"qiniu"   yaml:"qiniu"`  // 七牛云配置(对应INI的[qiniu]节、YAML的qiniu节点)
	ZapConf     Zap          `ini:"zap"     yaml:"zap"`    // Zap日志配置(对应INI的[zap]节、YAML的zap节点)
}

Config 总配置结构体(同时支持INI和YAML格式,标签分别对应)

type MysqlConfig

type MysqlConfig struct {
	Username string  `ini:"username" yaml:"username"` // 数据库用户名(示例:root)
	Password string  `ini:"password" yaml:"password"` // 数据库密码(为空则无需密码)
	Database string  `ini:"database" yaml:"database"` // 数据库名(需提前创建)
	Host     string  `ini:"host"     yaml:"host"`     // 数据库主机地址(示例:localhost)
	Port     string  `ini:"port"     yaml:"port"`     // 数据库端口(示例:3306)
	Timeout  float64 `ini:"timeout"  yaml:"timeout"`  // 连接超时时间(单位:秒,示例:300)
}

MysqlConfig MySQL数据库配置

type QiniuConfig

type QiniuConfig struct {
	AccessKey string `ini:"AccessKey" yaml:"accessKey"` // 七牛云AccessKey(从控制台获取)
	SecretKey string `ini:"SecretKey" yaml:"secretKey"` // 七牛云SecretKey(从控制台获取)
	Bucket    string `ini:"bucket"    yaml:"bucket"`    // 存储空间名(需提前创建)
	Domain    string `ini:"domain"    yaml:"domain"`    // 资源访问域名(示例:xxx.bkt.clouddn.com)
}

QiniuConfig 七牛云对象存储配置

type RedisConfig

type RedisConfig struct {
	Addr        string `ini:"addr"        yaml:"addr"`         // Redis地址(格式:IP:端口,示例:127.0.0.1:6379)
	Password    string `ini:"password"    yaml:"password"`     // Redis密码(为空则无密码)
	Database    int    `ini:"database"    yaml:"database"`     // 选中的数据库编号(0-15,默认0)
	MaxIdle     int    `ini:"max_idle"    yaml:"maxIdle"`      // 最大空闲连接数(示例:1000)
	MaxActive   int    `ini:"max_active"  yaml:"maxActive"`    // 最大活跃连接数(示例:5000)
	IdleTimeout int    `ini:"idle_timeout" yaml:"idleTimeout"` // 空闲连接超时时间(单位:秒,示例:7200=2小时)
}

RedisConfig Redis缓存配置

type ServerConfig

type ServerConfig struct {
	Port   string `ini:"port"   yaml:"port"`   // 服务端口(示例::582)
	Model  string `ini:"model"  yaml:"model"`  // 运行模式(debug/release)
	Db     string `ini:"db"     yaml:"db"`     // 数据库类型(示例:sqlite/mysql)
	Origin string `ini:"origin" yaml:"origin"` // 跨域允许的源地址(示例:http://localhost:8080
}

ServerConfig web服务配置

type Zap

type Zap struct {
	Level         string `mapstructure:"level" json:"level" yaml:"level" ini:"level"`                                    // 级别
	Prefix        string `mapstructure:"prefix" json:"prefix" yaml:"prefix" ini:"prefix"`                                // 日志前缀
	Format        string `mapstructure:"format" json:"format" yaml:"format" ini:"format"`                                // 输出
	Director      string `mapstructure:"director" json:"director"  yaml:"director" ini:"director"`                       // 日志文件夹
	EncodeLevel   string `mapstructure:"encode-level" json:"encode-level" yaml:"encodeLevel" ini:"encode-level"`         // 编码级
	StacktraceKey string `mapstructure:"stacktrace-key" json:"stacktrace-key" yaml:"stacktraceKey" ini:"stacktrace-key"` // 栈名

	MaxAge       int  `mapstructure:"max-age" json:"max-age" yaml:"maxAge" ini:"max-age"`                            // 日志留存时间
	ShowLine     bool `mapstructure:"show-line" json:"show-line" yaml:"showLine" ini:"show-line"`                    // 显示行
	LogInConsole bool `mapstructure:"log-in-console" json:"log-in-console" yaml:"logInConsole" ini:"log-in-console"` // 输出控制台
}

func (*Zap) TransportLevel

func (z *Zap) TransportLevel() zapcore.Level

TransportLevel 根据字符串转化为 zapcore.Level

func (*Zap) ZapEncodeLevel

func (z *Zap) ZapEncodeLevel() zapcore.LevelEncoder

ZapEncodeLevel 根据 EncodeLevel 返回 zapcore.LevelEncoder

Jump to

Keyboard shortcuts

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