configs

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package configs provides the config management log_config.go provides config management

Package configs provides config management

Package configs is the config of turl server

Index

Constants

View Source
const (
	// OutputConsole console output
	OutputConsole = "console"
	// OutputFile file output
	OutputFile = "file"

	// EncoderTypeText log format console encoder
	EncoderTypeText = "text"
	// EncoderTypeJSON log format json encoder
	EncoderTypeJSON = "json"

	// DebugLevel log level debug, equal to slog.LevelDebug
	DebugLevel = "debug"
	// InfoLevel log level info, equal to slog.LevelInfo
	InfoLevel = "info"
	// WarnLevlel log level warn, equal to slog.LevelWarn
	WarnLevlel = "warn"
	// ErrorLevel log level error, equal to slog.LevelError
	ErrorLevel = "error"
)

Variables

View Source
var Levels = map[string]slog.Level{
	"":         slog.LevelInfo,
	DebugLevel: slog.LevelDebug,
	InfoLevel:  slog.LevelInfo,
	WarnLevlel: slog.LevelWarn,
	ErrorLevel: slog.LevelError,
}

Levels slog level

Functions

This section is empty.

Types

type CacheConfig

type CacheConfig struct {
	// Redis is the redis config of turl server
	Redis *RedisConfig `json:"redis" yaml:"redis" mapstructure:"redis"`
	// LocalCache is the local cache config
	LocalCache *LocalCacheConfig `validate:"required" json:"local_cache" yaml:"local_cache" mapstructure:"local_cache"`
}

CacheConfig is the cache config of turl server

type FileConfig

type FileConfig struct {
	// Filepath log file path
	Filepath string `yaml:"filepath" mapstructure:"filepath" json:"filepath"`
	// MaxAge log file max age, days
	MaxAge int `yaml:"max_age" mapstructure:"max_age" json:"max_age"`
	// MaxBackups max backup files
	MaxBackups int `yaml:"max_backups" mapstructure:"max_backups" json:"max_backups"`
	// Compress log file is compress
	Compress bool `yaml:"compress" mapstructure:"compress" json:"compress"`
	// MaxSize max file size, MB
	MaxSize int `yaml:"max_size" mapstructure:"max_size" json:"max_size"`
}

FileConfig log file config

type LocalCacheConfig

type LocalCacheConfig struct {
	// TTL is the local cache ttl
	TTL time.Duration `validate:"required" json:"ttl" yaml:"ttl" mapstructure:"ttl"`
	// Capacity is the local cache capacity
	Capacity int `validate:"required" json:"capacity" yaml:"capacity" mapstructure:"capacity"`
	// MaxMemory max memory for value size in MB
	MaxMemory int `validate:"required" json:"max_memory" yaml:"max_memory" mapstructure:"max_memory"`
}

LocalCacheConfig is the local cache config of turl server

type LogConfig

type LogConfig struct {
	// Writers log output(OutputConsole, OutputFile)
	Writers []string `validate:"required,min=1" yaml:"writers" mapstructure:"writers" json:"writers"`
	// FileConfig log file config, if writers has file, must set file config
	FileConfig FileConfig `yaml:"file_config" mapstructure:"file_config" json:"file_config"`

	// Format log format type (console, json)
	Format string `validate:"required" yaml:"format" mapstructure:"format" json:"format"`
	// AddSource add source file and line
	AddSource bool `json:"add_source" yaml:"add_source" mapstructure:"add_source"`
	// Level log level debug info error...
	Level string `yaml:"level" mapstructure:"level" json:"level"`
}

LogConfig log output: console file remote

func (*LogConfig) String

func (c *LogConfig) String() string

type MySQLConfig

type MySQLConfig struct {
	// DSN is the data source name
	DSN string `json:"dsn" yaml:"dsn" mapstructure:"dsn"`
	// MaxIdleConn is the max open connections
	MaxConn int `validate:"required,min=1" json:"max_conn" yaml:"max_conn" mapstructure:"max_conn"`
}

MySQLConfig MySQLConfig Config

type RedisConfig

type RedisConfig struct {
	// Addr is the redis address
	Addr []string `validate:"required" json:"addr" yaml:"addr" mapstructure:"addr"`
	// DialTimeout Dial timeout for establishing new connections.
	// Default is 5 seconds.
	DialTimeout time.Duration `validate:"required" json:"dial_timeout" yaml:"dial_timeout" mapstructure:"dial_timeout"`
	// MaxIdleConn is the max open connections
	MaxConn int `validate:"required,min=1" json:"max_conn" yaml:"max_conn" mapstructure:"max_conn"`
	// TTL is the redis cache ttl
	TTL time.Duration `validate:"required" json:"ttl" yaml:"ttl" mapstructure:"ttl"`
}

RedisConfig Redis config

type ServerConfig

type ServerConfig struct {
	// Listen is the http server listen address of turl server
	Listen string `validate:"required,ip_addr|hostname" json:"listen" yaml:"listen" mapstructure:"listen"`
	// Port is the http server port of turl server
	Port int `validate:"required,min=1,max=65535" json:"port" yaml:"port" mapstructure:"port"`
	// Debug is the debug mode of turl server
	Debug bool `json:"debug" yaml:"debug" mapstructure:"debug"`
	// Domain is the domain of redirect url
	Domain string `validate:"required" json:"domain" yaml:"domain" mapstructure:"domain"`
	// Readonly is the read-only mode of turl server
	Readonly bool `json:"readonly" yaml:"readonly" mapstructure:"readonly"`
	// RequestTimeout is the http server request timeout of turl server
	RequestTimeout time.Duration `validate:"required" json:"request_timeout" yaml:"request_timeout" mapstructure:"request_timeout"`
	// GlobalRateLimitKey is the key of global rate limiter
	GlobalRateLimitKey string `validate:"required" json:"global_rate_limit_key" yaml:"global_rate_limit_key" mapstructure:"global_rate_limit_key"`
	// GlobalWriteRate is the token bucket rate of write api rate limiter
	GlobalWriteRate int `validate:"required,gt=0" json:"global_write_rate" yaml:"global_write_rate" mapstructure:"global_write_rate"`
	// GlobalWriteBurst is the token bucket burst of write api rate limiter
	GlobalWriteBurst int `validate:"required,min=1" json:"global_write_burst" yaml:"global_write_burst" mapstructure:"global_write_burst"`
	// StandAloneReadRate is the token bucket rate of read api rate limiter
	StandAloneReadRate int `validate:"required,gt=0" json:"stand_alone_read_rate" yaml:"stand_alone_read_rate" mapstructure:"stand_alone_read_rate"`
	// StandAloneReadBurst is the token bucket burst of read api rate limiter
	StandAloneReadBurst int `validate:"required,min=1" json:"stand_alone_read_burst" yaml:"stand_alone_read_burst" mapstructure:"stand_alone_read_burst"`

	// Log is the log config of turl server
	Log *LogConfig `validate:"required" json:"log" yaml:"log" mapstructure:"log"`
	// TDDL is the tddl config of turl server
	TDDL *TDDLConfig `validate:"required" json:"tddl" yaml:"tddl" mapstructure:"tddl"`
	// MySQL is the mysql config of turl server
	MySQL *MySQLConfig `validate:"required" json:"mysql" yaml:"mysql" mapstructure:"mysql"`
	// Cache is the cache config of turl server
	Cache *CacheConfig `validate:"required" json:"cache" yaml:"cache" mapstructure:"cache"`
}

ServerConfig is the config of turl server

func ReadFile

func ReadFile(path string, mp map[string]interface{}) (*ServerConfig, error)

ReadFile reads a yaml file and returns a ServerConfig.

func (*ServerConfig) Validate

func (c *ServerConfig) Validate() error

Validate validates the config if return nil, the config is valid

type TDDLConfig

type TDDLConfig struct {
	// Step is the step of the sequence
	Step uint64 `json:"step" yaml:"step" mapstructure:"step"`
	// SeqName is the name of the sequence
	SeqName string `json:"seq_name" yaml:"seq_name" mapstructure:"seq_name"`
	// StartNum is the start number of the sequence
	StartNum uint64 `json:"start_num" yaml:"start_num" mapstructure:"start_num"`
}

TDDLConfig is the configuration for tddl

Jump to

Keyboard shortcuts

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