conf

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLevelPriority

func GetLevelPriority(level zapcore.Level) zap.LevelEnablerFunc

GetLevelPriority 根据 zapcore.Level 获取 zap.LevelEnablerFunc Author [SliverHorn](https://github.com/SliverHorn)

Types

type AppConfig

type AppConfig struct {
	System SystemConfig `mapstructure:"system" json:"system" yaml:"system"`
	DB     DbConfig     `mapstructure:"db" json:"db" yaml:"db"`
	Zap    ZapConfig    `mapstructure:"zap" json:"zap" yaml:"zap"`
	Cors   *CorsConfig  `mapstructure:"cors" json:"cors" yaml:"cors"`
	JWT    *JwtConfig   `mapstructure:"jwt" json:"jwt" yaml:"jwt"`
}

func (*AppConfig) CorsEnabled

func (c *AppConfig) CorsEnabled() bool

func (*AppConfig) JwtEnabled

func (c *AppConfig) JwtEnabled() bool

type CacheConfig

type CacheConfig struct {
	Expiration      string `mapstructure:"expiration" json:"expiration" yaml:"expiration"`
	CleanupInterval string `mapstructure:"cleanup-interval" json:"cleanup_interval" yaml:"cleanup-interval"`
}

type CorsConfig

type CorsConfig struct {
	Enable    bool       `mapstructure:"enable" json:"enable" yaml:"enable"`
	Whitelist []CorsItem `mapstructure:"whitelist" json:"whitelist" yaml:"whitelist"`
	Blacklist []string   `mapstructure:"blacklist" json:"black_list" yaml:"blacklist"`
}

type CorsItem

type CorsItem struct {
	AllowOrigin      string `mapstructure:"allow-origin" json:"allow-origin" yaml:"allow-origin"`
	AllowMethods     string `mapstructure:"allow-methods" json:"allow-methods" yaml:"allow-methods"`
	AllowHeaders     string `mapstructure:"allow-headers" json:"allow-headers" yaml:"allow-headers"`
	ExposeHeaders    string `mapstructure:"expose-headers" json:"expose-headers" yaml:"expose-headers"`
	AllowCredentials bool   `mapstructure:"allow-credentials" json:"allow-credentials" yaml:"allow-credentials"`
}

type DbConfig

type DbConfig struct {
	Host     string `mapstructure:"host" json:"host" yaml:"host"`
	Port     uint   `mapstructure:"port" json:"port" yaml:"port"`
	UserName string `mapstructure:"username" json:"username" yaml:"username"`
	Password string `mapstructure:"password" json:"password" yaml:"password"`
	DbName   string `mapstructure:"dbname" json:"dbname" yaml:"dbname"`
	Debug    bool   `mapstructure:"debug" json:"debug" yaml:"debug"`
}

type Directories

type Directories struct {
	Static string `mapstructure:"static" json:"static" yaml:"static"`
	Doc    string `mapstructure:"doc" json:"doc" yaml:"doc"`
}

type Env

type Env string
const (
	EnvDev  Env = "dev"  // 开发环境
	EnvProd Env = "prod" // 正式环境
	EnvTest Env = "test" // 测试环境
)

type JwtConfig

type JwtConfig struct {
	Enable      bool   `mapstructure:"enable" json:"enable" yaml:"enable"`                   // 是否启用
	SigningKey  string `mapstructure:"signing-key" json:"signing-key" yaml:"signing-key"`    // jwt签名
	ExpiresTime string `mapstructure:"expires-time" json:"expires-time" yaml:"expires-time"` // 过期时间
	BufferTime  string `mapstructure:"buffer-time" json:"buffer-time" yaml:"buffer-time"`    // 缓冲时间
	Issuer      string `mapstructure:"issuer" json:"issuer" yaml:"issuer"`                   // 签发者
}

type Logger

type Logger struct {
	*zap.Logger
}

func (*Logger) Debugf

func (log *Logger) Debugf(format string, args ...interface{})

func (*Logger) Errorf

func (log *Logger) Errorf(format string, args ...interface{})

func (*Logger) Infof

func (log *Logger) Infof(format string, args ...interface{})

func (*Logger) Warnf

func (log *Logger) Warnf(format string, args ...interface{})

type SystemConfig

type SystemConfig struct {
	Name        string       `mapstructure:"name" json:"name" yaml:"name"`
	Env         Env          `mapstructure:"env" json:"env" yaml:"env"`
	Host        string       `mapstructure:"host" json:"host" yaml:"host"`
	Port        int          `mapstructure:"port" json:"port" yaml:"port"`
	Directories *Directories `mapstructure:"directories" json:"directories" yaml:"directories"`
	WebUrl      string       `mapstructure:"web-url" json:"web_url" yaml:"web-url"`
	LogRequest  *bool        `mapstructure:"log-request" yaml:"log-request"` // 记录系统请求
}

type ZapConfig

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

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

func (*ZapConfig) CustomTimeEncoder

func (z *ZapConfig) CustomTimeEncoder(t time.Time, encoder zapcore.PrimitiveArrayEncoder)

func (*ZapConfig) GetCores

func (z *ZapConfig) GetCores() []zapcore.Core

func (*ZapConfig) GetEncoder

func (z *ZapConfig) GetEncoder() zapcore.Encoder

func (*ZapConfig) GetEncoderConfig

func (z *ZapConfig) GetEncoderConfig() zapcore.EncoderConfig

func (*ZapConfig) GetEncoderCore

func (z *ZapConfig) GetEncoderCore(l zapcore.Level, level zap.LevelEnablerFunc) zapcore.Core

func (*ZapConfig) GetWriteSyncer

func (z *ZapConfig) GetWriteSyncer(level string) (zapcore.WriteSyncer, error)

func (*ZapConfig) Init

func (z *ZapConfig) Init() *Logger

func (*ZapConfig) TransportLevel

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

TransportLevel 根据字符串转化为 zapcore.Level Author [SliverHorn](https://github.com/SliverHorn)

func (*ZapConfig) ZapEncodeLevel

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

ZapEncodeLevel 根据 EncodeLevel 返回 zapcore.LevelEncoder Author [SliverHorn](https://github.com/SliverHorn)

Jump to

Keyboard shortcuts

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