config

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

日志相关配置

Index

Constants

View Source
const (
	DefaultAppName    = "application"
	DefaultServerType = "backend"
	DefaultPort       = 9445
)
View Source
const (
	MYSQL    DBTYPE = "mysql"
	SQLITE3  DBTYPE = "sqlite3"
	POSTGRES DBTYPE = "postgres"

	CACHEREDIS  CACHETYPE = "redis"
	CACHEMEMORY CACHETYPE = "memory"
)

Variables

This section is empty.

Functions

func LoadGlobalConfig

func LoadGlobalConfig(cfgPath string) (err error)

Types

type CACHETYPE added in v1.6.2

type CACHETYPE string

type CacheModel added in v1.6.2

type CacheModel string
const (
	ORMCacheDisable     CacheModel = "CacheDisable"
	ORMCacheOnlyPrimary CacheModel = "CacheOnlyPrimary"
	ORMCacheOnlySearch  CacheModel = "CacheOnlySearch"
	ORMCacheAll         CacheModel = "CacheAll"
)

func (CacheModel) Number added in v1.6.2

func (c CacheModel) Number() int

type DBConfig added in v1.6.2

type DBConfig struct {
	DBType   DBTYPE   `toml:"db_type" json:"db_type" env:"ORM_DBTYPE"`     // dbtype
	User     string   `toml:"user" json:"user" env:"ORM_USER"`             // user
	Password string   `toml:"password" json:"password" env:"ORM_PASSWORD"` // password
	Host     string   `toml:"host" json:"host" env:"ORM_HOST"`             // host
	Port     string   `toml:"port" json:"port" env:"ORM_PORT"`             // port
	Database string   `toml:"database" json:"database" env:"ORM_DATABASE"` // database
	Args     string   `toml:"orm_args" json:"orm_args" env:"ORM_ARGS"`     // args
	Cache    OrmCache `toml:"dbcache"`
}

DBConfig represents a database configuration

func (DBConfig) DefaultConfig added in v1.6.2

func (db DBConfig) DefaultConfig() DBConfig

func (DBConfig) TOML added in v1.6.2

func (db DBConfig) TOML() string

type DBTYPE added in v1.6.0

type DBTYPE string

type Discovery

type Discovery struct {
	Namespace   string         `toml:"namespace" json:"namespace" env:"DISCOVERY_NAMESPACE"`         // 命名空间
	Endpoints   []string       `toml:"endpoints" json:"endpoints" env:"DISCOVERY_ENDPOINTS"`         // 连接端点
	DialTimeout utils.Duration `toml:"dial_timeout" json:"dial_timeout" env:"DISCOVERY_DIALTIMEOUT"` // 连接超时时间
}

func (Discovery) DefaultConfig

func (ds Discovery) DefaultConfig() Discovery

func (Discovery) TOML

func (ds Discovery) TOML() string

type GinConfig

type GinConfig struct {
	App                 string         `toml:"app" json:"app" env:"GIN_APP"`                                               // application
	ServerType          string         `toml:"server_type" json:"server_type" env:"GIN_SERVERTYPE"`                        // 服务类型
	EnablePprof         bool           `toml:"enable_pprof" json:"enable_pprof" env:"GIN_ENABLEPPROF"`                     // pprof开关
	EnableHealth        bool           `toml:"enable_health" json:"enable_health" env:"GIN_ENABLEHEALTH"`                  // health开关
	EnableDebug         bool           `toml:"enable_debug" json:"enable_debug" env:"GIN_ENABLEDEBUG"`                     // debug开关
	EnableMetrics       bool           `toml:"enable_metrics" json:"enable_metrics" env:"GIN_ENABLEMETRICS"`               // metrics开关
	EnableCache         bool           `toml:"enable_cache" json:"enable_cache" env:"GIN_ENABLECACHE"`                     // 缓存开关
	EnableAuth          bool           `toml:"enable_auth" json:"enable_auth" env:"GIN_ENABLEAUTH"`                        // 签名权限开关
	EnableVerifyCommand bool           `toml:"enable_verify_command" json:"enable_verify_command" env:"GIN_VERIFYCOMMAND"` // 指令验证开关
	Port                int            `toml:"port" json:"port" env:"GIN_PORT"`                                            // port
	Trace               string         `toml:"trace" json:"trace" env:"GIN_TRACE"`                                         // Trace
	GracefulTimeout     utils.Duration `toml:"graceful_timeout" json:"graceful_timeout" env:"GIN_GRACEFULTIMEOUT"`         // GracefulTimeout
}

func (GinConfig) DefaultConfig

func (gcf GinConfig) DefaultConfig() GinConfig

func (GinConfig) ListenAddr

func (gcf GinConfig) ListenAddr() string

func (GinConfig) TOML

func (gcf GinConfig) TOML() string

type Global

type Global struct {
	Logging   `toml:"logging"`
	Metrics   `toml:"metrics"`
	Discovery `toml:"discovery"`
	GinConfig `toml:"gin"`
	RateLimit `toml:"ratelimit"`
	Temporary `toml:"temporary"`
	DBConfig  `toml:"database"`
}
var GlobalCfg Global

func (Global) TOML

func (g Global) TOML() string

type Logging

type Logging struct {
	IsTerminal bool   `toml:"isterminal" json:"isterminal" env:"LOGGING_ISTERMINAL"` // debug模式stdout输出
	Dir        string `toml:"dir" json:"dir" env:"LOGGING_DIR"`                      // 日志目录
	Filename   string `toml:"name" json:"name" env:"LOGGING_FILENAME"`               // 日志名称
	Level      string `toml:"level" json:"level" env:"LOGGING_LEVEL"`                // 打印日志等级
	MaxSize    uint16 `toml:"maxsize" json:"maxsize" env:"LOGGING_MAXSIZE"`          // 单日志尺寸
	MaxBackups uint16 `toml:"maxbackups" json:"maxbackups" env:"LOGGING_MAXBACKUPS"` // 日志备份数
	MaxAge     uint16 `toml:"maxage" json:"maxage" env:"LOGGING_MAXAGE"`             // 留旧日志文件的最大天数
}

Logging represents a logging configuration

func (Logging) DefaultConfig

func (l Logging) DefaultConfig() Logging

func (Logging) TOML

func (l Logging) TOML() string

type Metrics

type Metrics struct {
	FlushInterval          time.Duration     `toml:"flush_interval" json:"flush_interval" env:"METRICS_FLUSHINTERVAL"`                              // flush时间周期
	EnableGoRuntimeMetrics bool              `toml:"enable_goruntime_metrics" json:"enable_goruntime_metrics" env:"METRICS_ENABLEGORUNTIMEMETRICS"` // 是否收集goroutine相关信息
	MetricsPrefix          string            `toml:"metrics_prefix" json:"metrics_prefix" env:"METRICS_METRICSPREFIX"`                              // 自定义metric指标前缀
	MetricsTags            map[string]string `toml:"metrics_tags" json:"metrics_tags" env:"METRICS_METRICSTAGS"`                                    // 自定义metric自动填充kv数据
}

Metrics represents a logging configuration

func (Metrics) DefaultConfig

func (l Metrics) DefaultConfig() Metrics

func (Metrics) TOML

func (l Metrics) TOML() string

type OrmCache added in v1.6.2

type OrmCache struct {
	// cache type: redis, memory
	CacheType CACHETYPE `toml:"orm_cache_type" json:"orm_cache_type" env:"ORM_CACHE_TYPE" envDefault:"memory"`

	// 4 kinds of cache model
	CacheModel CacheModel `toml:"orm_cache_model" json:"orm_cache_model" env:"ORM_CACHE_MODEL" envDefault:"CacheOnlySearch"`

	// if user update/delete/create something in DB, we invalidate all cached data to ensure consistency,
	// else we do nothing to outdated cache.
	InvalidateWhenUpdate bool `toml:"orm_invalidate_when_update" json:"orm_invalidate_when_update" env:"ORM_INVALIDATE_WHEN_UPDATE" envDefault:"true"`

	// AsyncWrite if true, then we will write cache in async mode
	AsyncWrite bool `toml:"orm_async_write" json:"orm_async_write" env:"ORM_ASYNC_WRITE" envDefault:"true"`

	// CacheTTL cache ttl in ms, where 0 represents forever
	CacheTTL int64 `toml:"orm_cache_ttl" json:"orm_cache_ttl" env:"ORM_CACHE_TTL" envDefault:"5000"`

	// DisableCachePenetration if true, then we will not cache nil result
	DisableCachePenetrationProtect bool `` /* 152-byte string literal not displayed */

	CacheCfg OrmCacheCfg `toml:"dbcachecfg"`
}

type OrmCacheCfg added in v1.6.2

type OrmCacheCfg struct {
	// host:port address.
	Addr string `toml:"orm_cache_addr" json:"orm_cache_addr" env:"ORM_CACHE_ADDR"`
	// Use the specified Username to authenticate the current connection
	// with one of the connections defined in the ACL list when connecting
	// to a Redis 6.0 instance, or greater, that is using the Redis ACL system.
	Username string `toml:"orm_cache_username" json:"orm_cache_username" env:"ORM_CACHE_USERNAME"`
	// Optional password. Must match the password specified in the
	// requirepass server configuration option (if connecting to a Redis 5.0 instance, or lower),
	// or the User Password when connecting to a Redis 6.0 instance, or greater,
	// that is using the Redis ACL system.
	Password string `toml:"orm_cache_password" json:"orm_cache_password" env:"ORM_CACHE_PASSWORD"`
	// Database to be selected after connecting to the server.
	DB int `toml:"orm_cache_dbid" json:"orm_cache_dbid" env:"ORM_CACHE_DBID"`
}

type RateLimit

type RateLimit struct {
	QPS   int `toml:"qps" json:"qps" env:"GIN_RATELIMIT_QPS"`       // qps
	Burst int `toml:"burst" json:"burst" env:"GIN_RATELIMIT_BURST"` // 并发数
}

func (RateLimit) DefaultConfig

func (rl RateLimit) DefaultConfig() RateLimit

func (RateLimit) TOML

func (rl RateLimit) TOML() string

type Temporary

type Temporary struct {
	MaxBufferSize int64  `toml:"max_buffer_size" json:"max_buffer_size" env:"TEMPORARY_MAX_BUFFER_SIZE"` // 最大使用内存空间, 超过时则转化成文件
	FileDir       string `toml:"file_dir" json:"file_dir" env:"TEMPORARY_FILE_DIR"`                      // 临时文件目录
	FilePattern   string `toml:"file_pattern" json:"file_pattern" env:"TEMPORARY_FILE_PATTERN"`          // 临时文件名格式
	MaxUploadSize int64  `toml:"max_upload_size" json:"max_upload_size" env:"TEMPORARY_MAX_UPLOAD_SIZE"` // 最大上传文件大小
}

Temporary represents a logging configuration

func (Temporary) DefaultConfig

func (l Temporary) DefaultConfig() Temporary

func (Temporary) TOML

func (l Temporary) TOML() string

Directories

Path Synopsis
配置加载后, 联动更新各个模块的全局变量.
配置加载后, 联动更新各个模块的全局变量.

Jump to

Keyboard shortcuts

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