config

package
v1.0.4-snapshot Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultGroup = "DEFAULT_GROUP"

	LoggerDataId     = "logger"
	MySqlDataId      = "mysql"
	RedisDataId      = "redis"
	OssDataOddId     = "oss"
	PowerJobDataId   = "powerjob"
	GrpcDataId       = "grpc"
	PrometheusDataId = "prometheus"
	WebDataId        = "web"
)

Variables

Functions

func InitConfig

func InitConfig(ctx context.Context, localConfigPath string, bootConfig *BootstrapConfig)

初始化配置

func RegisterConfigChangeHandler

func RegisterConfigChangeHandler(dataId, group string, handler ChangeHandler)

RegisterConfigChangeHandler 注册配置变更监听

Types

type BootOption

type BootOption func(*BootstrapConfig)

func WithCustomerConfigs

func WithCustomerConfigs(name string, configs interface{}) BootOption

func WithWebApi

func WithWebApi(api []WebGroup) BootOption

func WithWebMiddlewares

func WithWebMiddlewares(hf []gin.HandlerFunc) BootOption

func WithWebValidators

func WithWebValidators(validators map[string]validator.Func) BootOption

type BootstrapConfig

type BootstrapConfig struct {
	WebApi          []WebGroup
	WebMiddlewares  []gin.HandlerFunc
	WebValidators   map[string]validator.Func
	CustomerConfigs map[string]interface{}
}

type ChangeHandler

type ChangeHandler func(data string)

ChangeHandler 配置变更处理器函数

type CustomConfig

type CustomConfig struct {
	Name         string
	ConfigStruct *interface{}
}

type GlobalConfig

type GlobalConfig struct {
	NaCos     *NaCosConfig     `yaml:"nacos"`
	WebServer *WebServerConfig `yaml:"web-server"`
	Logger    *LoggerConfig    `yaml:"logger"`
	MySQL     *MySqlConfig     `yaml:"mysql"`
	Redis     *RedisConfig     `yaml:"redis"`
}
var GlobalConf *GlobalConfig

type LoggerConfig

type LoggerConfig struct {
	Level      string `yaml:"level"`       // 日志级别
	Filename   string `yaml:"filename"`    // 日志文件名
	MaxSize    int    `yaml:"max-size"`    // 日志文件最大大小
	MaxAge     int    `yaml:"max-age"`     // 日志文件最大保存时间
	MaxBackups int    `yaml:"max-backups"` // 日志文件最大保存个数
	Compress   bool   `yaml:"compress"`    // 日志文件是否压缩
}

LoggerConfig 日志配置结构体

type MySqlConfig

type MySqlConfig struct {
	Host        string `yaml:"host"`
	Port        int    `yaml:"port"`
	UserName    string `yaml:"user-name"`
	Password    string `yaml:"password"`
	DbName      string `yaml:"db-name"`
	MaxIdle     int    `yaml:"max-idle"`      //最大空闲连接
	MaxConn     int    `yaml:"max-conn"`      //最大连接数
	MaxLife     int    `yaml:"max-life"`      //连接生命周期,单位为分钟
	MaxIdleTime int    `yaml:"max-idle-time"` //连接空闲时间,单位为分钟
}

MySqlConfig mysql配置

type NaCosConfig

type NaCosConfig struct {
	ServerAddr string `yaml:"server-addr"` // NaCos服务器地址
	UserName   string `yaml:"user-name"`   // NaCos用户名
	Password   string `yaml:"password"`    // NaCos <PASSWORD>
	Namespace  string `yaml:"namespace"`   // NaCos命名空间
}

NaCosConfig 专门用于NaCos的配置信息

type Option

type Option func(*GlobalConfig)

func WithLoggerConfig

func WithLoggerConfig(logger *LoggerConfig) Option

func WithMySqlConfig

func WithMySqlConfig(mysql *MySqlConfig) Option

func WithNaCosConfig

func WithNaCosConfig(nc *NaCosConfig) Option

func WithRedisConfig

func WithRedisConfig(redis *RedisConfig) Option

type RedisConfig

type RedisConfig struct {
	ServerAddress string `yaml:"server-address"` // Redis服务器地址
	Password      string `yaml:"password"`       // Redis密码
	DB            int    `yaml:"db"`             // Redis数据库
	PoolSize      int    `yaml:"pool-size"`      // Redis连接池大小
	MinIdleCones  int    `yaml:"min-idle-cones"` // Redis最小空闲连接数
}

RedisConfig Redis配置结构体

type WebGroup

type WebGroup struct {
	Path     string
	WebPaths []WebPath
}

type WebPath

type WebPath struct {
	Path    string
	Method  string
	Handler gin.HandlerFunc
}

type WebServerConfig

type WebServerConfig struct {
	Port        string `yaml:"port"`
	ContextPath string `yaml:"context-path"`
}

Jump to

Keyboard shortcuts

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