config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppConfig

type AppConfig struct {
	Name    string `mapstructure:"name"`
	Version string `mapstructure:"version"`
	Mode    string `mapstructure:"mode"` // debug/release/test
}

AppConfig 应用配置

type Config

type Config struct {
	// 应用基础配置
	App AppConfig `mapstructure:"app"`

	// 服务器配置
	Server ServerConfig `mapstructure:"server"`

	// 数据库配置
	Database DatabaseConfig `mapstructure:"database"`

	// Redis 配置
	Redis RedisConfig `mapstructure:"redis"`

	// JWT 配置
	JWT JWTConfig `mapstructure:"jwt"`

	// 日志配置
	Log LogConfig `mapstructure:"log"`
}

Config 通用配置结构

func Load

func Load(configPath string) (*Config, error)

Load 加载配置文件

func (*Config) Validate

func (c *Config) Validate() error

Validate 验证配置的有效性

type DatabaseConfig

type DatabaseConfig struct {
	MySQL MySQLOptions `mapstructure:"mysql"`
}

DatabaseConfig 数据库配置

type JWTConfig

type JWTConfig struct {
	Secret        string `mapstructure:"secret"`
	Expire        int    `mapstructure:"expire"`
	TokenID       string `mapstructure:"token-id"`
	BlacklistPath string `mapstructure:"blacklist-path"`
}

JWTConfig JWT 配置

type LogConfig

type LogConfig struct {
	DisableCaller     bool   `mapstructure:"disable-caller"`
	DisableStacktrace bool   `mapstructure:"disable-stacktrace"`
	Level             string `mapstructure:"level"`
	Format            string `mapstructure:"format"`
	Dir               string `mapstructure:"dir"`
}

LogConfig 日志配置

type MySQLOptions

type MySQLOptions struct {
	Host                  string        `mapstructure:"host"`
	Username              string        `mapstructure:"username"`
	Password              string        `mapstructure:"password"`
	Database              string        `mapstructure:"database"`
	MaxIdleConnections    int           `mapstructure:"max-idle-connections"`
	MaxOpenConnections    int           `mapstructure:"max-open-connections"`
	MaxConnectionLifeTime time.Duration `mapstructure:"max-connection-life-time"`
	LogLevel              int           `mapstructure:"log-level"`
}

MySQLOptions MySQL 配置选项

type RedisConfig

type RedisConfig struct {
	Addr     string `mapstructure:"addr"`
	Port     string `mapstructure:"port"`
	Password string `mapstructure:"password"`
	DB       int    `mapstructure:"db"`
}

RedisConfig Redis 配置

type ServerConfig

type ServerConfig struct {
	HTTPAddr  string `mapstructure:"http-addr"`
	HTTPSAddr string `mapstructure:"https-addr"`
	TLSCert   string `mapstructure:"tls-cert"`
	TLSKey    string `mapstructure:"tls-key"`
}

ServerConfig 服务器配置

Jump to

Keyboard shortcuts

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