config

package
v0.0.0-...-2198923 Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ApplicationConfig = new(Application)
View Source
var CacheConfig = new(Cache)
View Source
var (
	// DatabaseConfig  = new(db.ConnectionOptions)
	DatabasesConfig = make(map[string]*db.ConnectionOptions)
)
View Source
var ExtConfig = new(Extend)
View Source
var (
	ExtendConfig interface{}
)
View Source
var FilesystemConfig = new(Filesystem)
View Source
var LoggerConfig = new(Logger)
View Source
var (
	RedisConfig = new(Redis)
)
View Source
var ServerConfig = new(map[string]Server)

Functions

func GetRedisClient

func GetRedisClient() *redis.Client

GetRedisClient 获取redis客户端

func SetRedisClient

func SetRedisClient(c *redis.Client)

SetRedisClient 设置redis客户端

func Setup

func Setup()

@title Setup @description Setup 载入配置文件 @auth cpYun 2022/7/22 10:00

Types

type AliyunOSS

type AliyunOSS struct {
}

type Application

type Application struct {
	Mode     string `json:"mode" yaml:"mode"`           //环境配置 dev开发环境 test测试环境 prod线上环境
	Name     string `json:"name" yaml:"name"`           // 服务名称
	EnableDp bool   `json:"enable-dp" yaml:"enable-dp"` // 数据权限功能开关
}

type Cache

type Cache struct {
	Driver string `yaml:"driver"`
	Redis  Redis
	Memory interface{}
}

func (*Cache) Setup

func (e *Cache) Setup() error

Setup 构造cache 顺序 redis > 其他 > memory

type Config

type Config struct {
	Application *Application                     `mapstructure:"application" json:"application" yaml:"application"`
	Logger      *Logger                          `mapstructure:"logger" json:"logger" yaml:"logger"`
	Cache       *Cache                           `mapstructure:"cache" yaml:"cache" json:"cache"`
	Databases   map[string]*db.ConnectionOptions `json:"databases" yaml:"databases"`
	Filesystem  *Filesystem                      `mapstructure:"filesystem" json:"mysql" yaml:"filesystem"`
	Redis       *Redis                           `mapstructure:"redis" json:"redis" yaml:"redis"`
	Server      map[string]Server                `mapstructure:"server" json:"server" yaml:"server"`
	Extend      interface{}                      `yaml:"extend"`
}

func (*Config) OnChange

func (c *Config) OnChange()

type Demo

type Demo struct {
	Name string
}

type Extend

type Extend struct {
	Demo Demo // 这里配置对应配置文件的结构即可
}

Extend 扩展配置

extend:
  demo:
    name: demo-name

Example: config.ExtConfig......!!

type Filesystem

type Filesystem struct {
	Driver    string
	Local     interface{}
	Minio     Minio
	Qiniu     Qiniu
	AliyunOSS AliyunOSS
}

type Logger

type Logger struct {
	Type          string    `mapstructure:"type" json:"type" yaml:"type"`
	Level         string    `mapstructure:"level" json:"level" yaml:"level"`                            // 级别
	TimeFormat    string    `mapstructure:"time-format" json:"time-format" yaml:"time-format"`          // 时间格式
	Prefix        string    `mapstructure:"prefix" json:"prefix" yaml:"prefix"`                         // 日志前缀
	Path          string    `mapstructure:"path" json:"path"  yaml:"path"`                              // 日志文件
	ShowLine      bool      `mapstructure:"show-line" json:"show-line" yaml:"show-line"`                // 显示行
	EncodeLevel   string    `mapstructure:"encode-level" json:"encode-level" yaml:"encode-level"`       // 编码级
	StacktraceKey string    `mapstructure:"stacktrace-key" json:"stacktrace-key" yaml:"stacktrace-key"` // 栈名
	Stdout        string    `mapstructure:"stdout" json:"stdout" yaml:"stdout"`                         // 输出控制台
	Cut           LoggerCut `mapstructure:"cut" json:"cut" yaml:"cut"`                                  // 日志裁切
}

func (Logger) Setup

func (e Logger) Setup()

Setup 设置logger

type LoggerCut

type LoggerCut struct {
	Cap        uint `mapstructure:"cap" json:"cap" yaml:"cap"`                     // 裁切 MB
	MaxAge     uint `mapstructure:"max-age" json:"max-age" yaml:"max-age"`         // 最大备份天数
	MaxBackups uint `mapstructure:"max-age" json:"max-backups" yaml:"max-backups"` // 最大备份数
	Compress   bool `mapstructure:"compress" json:"compress" yaml:"compress"`      // 是否压缩
}

type Minio

type Minio struct {
	Endpoint        string
	AccessKeyID     string `mapstructure:"access-key-id" json:"access-key-id" yaml:"access-key-id"`
	SecretAccessKey string `mapstructure:"secret-access-key" json:"secret-access-key" yaml:"secret-access-key"`
	Secure          bool   `mapstructure:"secure" json:"secure" yaml:"secure"`
	Region          string `mapstructure:"region" json:"region" yaml:"region"`
	Bucket          string `mapstructure:"bucket" json:"bucket" yaml:"bucket"`
}

type Qiniu

type Qiniu struct {
}

type Redis

type Redis struct {
	Dsn string `yaml:"dsn" json:"dsn"`
	Tls *Tls   `yaml:"tls" json:"tls"`
}

func (*Redis) GetRedisOptions

func (e *Redis) GetRedisOptions() (*redis.Options, error)

type Server

type Server struct {
	Host         string `mapstructure:"host" json:"host" yaml:"host"` // 监听地址
	Port         int    `mapstructure:"port" json:"port" yaml:"port"` // 监听端口
	ReadTimeout  int    `json:"read-timeout" yaml:"read-timeout"`     // 读超时
	WriteTimeout int    `json:"write-timeout" yaml:"write-timeout"`   // 写超时
}

type Tls

type Tls struct {
	Cert string `yaml:"cert" json:"cert"`
	Key  string `yaml:"key" json:"key"`
	Ca   string `yaml:"ca" json:"ca"`
}

Jump to

Keyboard shortcuts

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