config

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JSON = "json"
	YAML = "yaml"
	TOML = "toml"
	INI  = "ini"
)

支持的配置后缀

View Source
const (
	Local      = "local"      // 本地环境
	Develop    = "develop"    // 测试环境
	Release    = "release"    // 预发布环境
	Production = "production" // 生产环境
)

配置区分

Variables

This section is empty.

Functions

func GetEnv

func GetEnv() string

func InitConfig

func InitConfig(env string, configs ...interface{})

InitConfig 需要设置默认环境变量,当系统中存在环境变量值时,会优先使用 系统标量(DANDELION_ENV)。configs 为自定义配置,可系统加载用户自定 义配置

func LoadCustomConfig

func LoadCustomConfig(configs ...interface{})

Types

type Config

type Config struct {
	DB         *DB         `json:"db" yaml:"db"`
	Redis      *Redis      `json:"redis" yaml:"redis"`
	Logger     *Logger     `json:"logger" yaml:"logger"`
	HttpServer *HttpServer `json:"http_server" yaml:"httpServer"`
	RpcServer  *RpcServer  `json:"rpc_server" yaml:"rpcServer"`
	RpcClient  *RpcClient  `json:"rpc_client" yaml:"rpcClient"`
	Tracer     *Tracer     `json:"tracer" yaml:"tracer"`
}
var Conf Config

type DB

type DB struct {
	DBType        string   `json:"db_type" yaml:"dbType"`
	MaxOpenConn   int      `json:"max_open_conn" yaml:"maxOpenConn"`
	MaxIdleConn   int      `json:"max_idle_conn" yaml:"maxIdleConn"`
	MaxLifeTime   int      `json:"max_life_time" yaml:"maxLifeTime"`
	MaxIdleTime   int      `json:"max_idle_time" yaml:"maxIdleTime"`
	Level         int      `json:"level" yaml:"level"`
	SlowThreshold string   `json:"slow_threshold" yaml:"slowThreshold"`
	Master        *Master  `json:"master" yaml:"master"`
	Slaves        []*Slave `json:"slaves" yaml:"slaves"`
}

type HttpServer

type HttpServer struct {
	Port int32 `json:"port" yaml:"port"`
}

type Logger

type Logger struct {
	ConsoleShow    bool `json:"console_show" yaml:"consoleShow"`
	ConsoleLevel   int  `json:"console_level" yaml:"consoleLevel"`
	FileWrite      bool `json:"file_write" yaml:"fileWrite"`
	FileLevel      int  `json:"file_level" yaml:"fileLevel"`
	MultiFileWrite bool `json:"multi_file_write" yaml:"multiFileWrite"`
	MultiFileLevel int  `json:"multi_file_level" yaml:"multiFileLevel"`
}

type Master

type Master struct {
	User     string `json:"user" yaml:"user"`
	Password string `json:"password" yaml:"password"`
	Host     string `json:"host" yaml:"host"`
	Port     string `json:"port" yaml:"port"`
	Database string `json:"data_base" yaml:"database"`
}

type Redis

type Redis struct {
	RedisType    string   `json:"redis_type" yaml:"redisType"` //cluster,alone,sentinel
	StartAddr    []string `json:"start_addr" yaml:"startAddr"` // Startup nodes
	Active       int      `json:"active" yaml:"active"`
	Idle         int      `json:"idle" yaml:"idle"`
	Auth         string   `json:"auth" yaml:"auth"`
	ConnTimeout  string   `json:"conn_timeout" yaml:"connTimeout"`   // Connection timeout
	ReadTimeout  string   `json:"read_timeout" yaml:"readTimeout"`   // Read timeout
	WriteTimeout string   `json:"write_timeout" yaml:"writeTimeout"` // Write timeout
	IdleTimeout  string   `json:"idle_timeout" yaml:"idleTimeout"`
}

type RpcClient

type RpcClient struct {
	ClientName      string   `json:"client_name" yaml:"clientName"`
	BasePath        string   `json:"base_path" yaml:"basePath"`
	RegisterPlugin  string   `json:"register_plugin" yaml:"registerPlugin"`
	RegisterServers []string `json:"register_servers" yaml:"registerServers"`
	FailRetryModel  int      `json:"fail_retry_model" yaml:"failRetryModel"`
	BalanceModel    int      `json:"balance_model" yaml:"balanceModel"`
	PoolSize        int      `json:"pool_size" yaml:"poolSize"`
}

type RpcServer

type RpcServer struct {
	ServerName      string   `json:"server_name" yaml:"serverName"`
	BasePath        string   `json:"base_path" yaml:"basePath"`
	RegisterPlugin  string   `json:"register_plugin" yaml:"registerPlugin"`
	RegisterServers []string `json:"register_servers" yaml:"registerServers"`
	Addr            string   `json:"addr" yaml:"addr"`
	Port            int      `json:"port" yaml:"port"`
}

type Slave

type Slave struct {
	User     string `json:"user" yaml:"user"`
	Password string `json:"password" yaml:"password"`
	Host     string `json:"host" yaml:"host"`
	Port     string `json:"port" yaml:"port"`
	Database string `json:"data_base" yaml:"database"`
}

type Tracer

type Tracer struct {
	OpenTrace bool   `json:"open_trace" yaml:"openTrace"`
	TraceName string `json:"trace_name" yaml:"traceName"`
	Host      string `json:"host" yaml:"host"`
}

Jump to

Keyboard shortcuts

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