config

package
v0.0.0-...-3030a97 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DatabaseConfig  = new(Database)
	DatabasesConfig = make(map[string]*Database)
)
View Source
var ApplicationConfig = new(Application)
View Source
var CacheConfig = new(Cache)
View Source
var CasbinConfig = new(Casbin)
View Source
var ExtConfig = new(Extend)
View Source
var FilesystemConfig = new(Filesystem)
View Source
var JwtConfig = new(Jwt)
View Source
var LockerConfig = new(Locker)
View Source
var LoggerConfig = new(Logger)
View Source
var QueueConfig = new(Queue)

Functions

func GetRedisClient

func GetRedisClient() *redis.Client

GetRedisClient 获取redis客户端

func SetRedisClient

func SetRedisClient(c *redis.Client)

SetRedisClient 设置redis客户端

func Setup

func Setup(fs ...SetOptionFuc)

Setup @description Setup 载入配置文件 @auth cpYun 时间(2022/7/22 10:00 ) @param s string "配置文件路径" @param fs func "回调函数" @return

Types

type AliyunOSS

type AliyunOSS struct {
}

type Application

type Application struct {
	Mode         string `json:"mode" yaml:"mode"`                   //环境配置 dev开发环境 test测试环境 prod线上环境
	Host         string `json:"host" yaml:"host"`                   // 服务器ip,默认使用 0.0.0.0
	Port         int    `json:"port" yaml:"port"`                   // 端口号
	Name         string `json:"name" yaml:"name"`                   // 服务名称
	ReadTimeout  int    `json:"read-timeout" yaml:"read-timeout"`   // 读超时
	WriteTimeout int    `json:"write-timeout" yaml:"write-timeout"` // 写超时
	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() (storage.AdapterCache, error)

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

type Casbin

type Casbin struct {
	ModelPath string `mapstructure:"model-path" json:"model-path" yaml:"model-path"` //存放casbin模型的相对路径
	Adapter   string `mapstructure:"adapter" json:"adapter" yaml:"adapter"`          //适配器
	Watcher   string `mapstructure:"watcher" json:"watcher" yaml:"watcher"`          //监听
	Redis     *Redis
}

type Config

type Config struct {
	Application *Application          `mapstructure:"application" json:"application" yaml:"application"`
	Database    *Database             `json:"database" yaml:"database"`
	Databases   *map[string]*Database `json:"databases" yaml:"databases"`
	Logger      *Logger               `mapstructure:"logger" json:"logger" yaml:"logger"`
	Cache       *Cache                `mapstructure:"cache" yaml:"cache" json:"cache"`
	Filesystem  *Filesystem           `mapstructure:"filesystem" json:"mysql" yaml:"filesystem"`
	Queue       *Queue                `json:"queue" yaml:"queue"`
	Locker      *Locker               `json:"locker" yaml:"locker"`
	JWT         *Jwt                  `mapstructure:"jwt" json:"jwt" yaml:"jwt"`
	Redis       Redis                 `mapstructure:"redis" json:"redis" yaml:"redis"`
	Casbin      *Casbin               `mapstructure:"casbin" json:"casbin" yaml:"casbin"`
	Extend      interface{}           `yaml:"extend"`
	// contains filtered or unexported fields
}
var (
	ExtendConfig interface{}
	Settings     *Config
)

func (*Config) OnChange

func (c *Config) OnChange()

type DBResolverConfig

type DBResolverConfig struct {
	Sources  []string `mapstructure:"sources" json:"sources" yaml:"sources"`
	Replicas []string `mapstructure:"replicas" json:"replicas" yaml:"replicas"`
	Policy   string   `mapstructure:"policy" json:"policy" yaml:"policy"`
	Tables   []string `mapstructure:"tables" json:"tables" yaml:"tables"`
}

type Database

type Database struct {
	Driver          string             `mapstructure:"driver" json:"driver" yaml:"driver"`
	Source          string             `mapstructure:"source" json:"source" yaml:"source"`
	ConnMaxIdleTime int                `mapstructure:"conn-max-idle-time" json:"conn-max-idle-time" yaml:"conn-max-idle-time"`
	ConnMaxLifeTime int                `mapstructure:"conn-max-life-time" json:"conn-max-life-time" yaml:"conn-max-life-time"`
	MaxIdleConns    int                `mapstructure:"max-idle-conns" json:"max-idle-conns" yaml:"max-idle-conns"` // 空闲中的最大连接数
	MaxOpenConns    int                `mapstructure:"max-open-conns" json:"max-open-conns" yaml:"max-open-conns"` // 打开到数据库的最大连接数
	LoggerMode      string             `mapstructure:"logger-mode" json:"logger-mode" yaml:"logger-mode"`
	Registers       []DBResolverConfig `mapstructure:"registers" json:"registers" yaml:"registers"`
}

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 Jwt

type Jwt struct {
	SigningKey  string `mapstructure:"signing-key" json:"signing-key" yaml:"signing-key"`    // jwt签名
	ExpiresTime int64  `mapstructure:"expires-time" json:"expires-time" yaml:"expires-time"` // 过期时间
	BufferTime  int64  `mapstructure:"buffer-time" json:"buffer-time" yaml:"buffer-time"`    // 缓冲时间
	Issuer      string `mapstructure:"issuer" json:"issuer" yaml:"issuer"`                   // 签发者
}

type Locker

type Locker struct {
	Driver string `json:"driver" yaml:"driver"`
	Redis  *Redis
}

func (Locker) Empty

func (l Locker) Empty() bool

func (Locker) Setup

func (l Locker) Setup() (storage.AdapterLocker, error)

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 Queue

type Queue struct {
	Redis  *QueueRedis
	Memory *QueueMemory
	NSQ    *QueueNSQ `json:"nsq" yaml:"nsq"`
}

func (Queue) Empty

func (e Queue) Empty() bool

Empty 空设置

func (Queue) Setup

func (e Queue) Setup() (storage.AdapterQueue, error)

Setup 启用顺序 redis > 其他 > memory

type QueueMemory

type QueueMemory struct {
	PoolSize uint
}

type QueueNSQ

type QueueNSQ struct {
	//NSQOptions
	ChannelPrefix string
}

type QueueRedis

type QueueRedis struct {
	Redis
	Producer *redisqueue.ProducerOptions
	Consumer *redisqueue.ConsumerOptions
}

type Redis

type Redis struct {
	Network    string `yaml:"network" json:"network"` //
	Addr       string `yaml:"addr" json:"addr"`       // 服务器地址:端口
	Username   string `yaml:"username" json:"username"`
	Password   string `yaml:"password" json:"password"`
	DB         int    `yaml:"db" json:"db"`
	PoolSize   int    `yaml:"pool-size" json:"pool-size"`
	Tls        *Tls   `yaml:"tls" json:"tls"`
	MaxRetries int    `yaml:"max-retries" json:"max-retries"`
}

func (Redis) GetRedisOptions

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

type SetOptionFuc

type SetOptionFuc func(*setOptions)

func WithCallback

func WithCallback(fs ...func()) SetOptionFuc

func WithSource

func WithSource(s ...source.Source) SetOptionFuc

type System

type System struct {
	Env            string `mapstructure:"env" json:"env" yaml:"env"`                                     // 环境值
	Addr           int    `mapstructure:"addr" json:"addr" yaml:"addr"`                                  // 端口值
	DatabaseDriver string `mapstructure:"database-driver" json:"database-driver" yaml:"database-driver"` // 数据库类型:mysql(默认)|sqlite|sqlserver|postgresql
	OssType        string `mapstructure:"oss-type" json:"oss-type" yaml:"oss-type"`                      // Oss类型
	UseMultipoint  bool   `mapstructure:"use-multipoint" json:"use-multipoint" yaml:"use-multipoint"`    // 多点登录拦截
	UseRedis       bool   `mapstructure:"use-redis" json:"use-redis" yaml:"use-redis"`                   // 使用redis
	LimitCountIP   int    `mapstructure:"iplimit-count" json:"iplimit-count" yaml:"iplimit-count"`
	LimitTimeIP    int    `mapstructure:"iplimit-time" json:"iplimit-time" yaml:"iplimit-time"`
}

System Deprecated: Use Application instead

type Tls

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

type Zap

type Zap struct {
	Level         string `mapstructure:"level" json:"level" yaml:"level"`                            // 级别
	Format        string `mapstructure:"format" json:"format" yaml:"format"`                         // 输出
	Prefix        string `mapstructure:"prefix" json:"prefix" yaml:"prefix"`                         // 日志前缀
	Director      string `mapstructure:"director" json:"director"  yaml:"director"`                  // 日志文件夹
	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"` // 栈名
	LogInConsole  bool   `mapstructure:"log-in-console" json:"log-in-console" yaml:"log-in-console"` // 输出控制台
}

Zap Deprecated: Use Logger instead

Jump to

Keyboard shortcuts

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