config

package
v0.0.0-...-2ebd195 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DEFAULT_DIR = "./conf/"
View Source
var NotifyFunc []OnConfigChange

Functions

func AtreusCliConfigInit

func AtreusCliConfigInit()

func AtreusSvcConfigInit

func AtreusSvcConfigInit()

func Init

func Init(file, suffix string)

func InitConfigAbsolutePath

func InitConfigAbsolutePath(dir, file, suffix string)

初始化配置文件

func Keys

func Keys(c *Config) []string

返回该conf当前级别下所有的key

func Register

func Register(f OnConfigChange)

func Set

func Set(key string, value interface{})

func SetDefaultConfDir

func SetDefaultConfDir(dir string)

Types

type AclConfig

type AclConfig struct {
	On          bool     `json:"on-off"`
	WhiteIpList []string `json:white_list`
}

type AtreusCliConfig

type AtreusCliConfig struct {
	//Cli config
	CliConf *CliConfig

	//Dial
	SrvDnsConf *SrvDnsConfig

	//TLS config
	TlsConf *TlsConfig

	//Service Register
	RegistryConf *RegistryConfig

	//Log
	LogConf *LogConfig

	//Auth
	AuthConf *AuthConfig

	//Breaker
	BreakerConf *BreakerConfig

	//retry
	RetryConf *ClientRetryConfig

	//tracer
	TracingConf *TracingConfig
}

func GetAtreusCliConfig

func GetAtreusCliConfig() *AtreusCliConfig

type AtreusSvcConfig

type AtreusSvcConfig struct {
	//Server config
	SrvConf *SrvConfig `json:"srv_conf"`

	//TLS config
	TlsConf *TlsConfig `json:"tls_conf"`

	//Service Register
	RegistryConf *RegistryConfig `json:"registry_conf"`

	//Limiter
	LimiterConf *LimiterConfig `json:"limiter_conf"`
	//Etcd
	EtcdConf *EtcdConfig `json:"etcd_conf"`

	//Weight
	WeightConf *WeightConfig `json:"weight_conf"`

	//Log
	LogConf *LogConfig `json:"log_conf"`

	//Auth
	AuthConf *AuthConfig `json:"auth_conf"`

	//ACL
	AclConf *AclConfig `json:"acl_conf"`

	//tracer
	TracingConf *TracingConfig `json:"tracing"`

	//system collector
	SysCollectorConf *SysCollectorConfig `json:"collector"`
}

func GetAtreusSvcConfig

func GetAtreusSvcConfig() *AtreusSvcConfig

type AuthConfig

type AuthConfig struct {
	On bool `json:"on-off"`
}

type BreakerConfig

type BreakerConfig struct {
	On                         bool          `json:"on-off"`
	BreakerType                string        `json:"type"` //熔断器类型
	MaxRequestsForHalfOpen     int           `json:"max_request"`
	Interval                   time.Duration `json:"interval"`
	TimeoutForOpen             time.Duration `json:"timeout"`
	ReadyToTripForTotalrequets int           `json:"r2t_total_request"` //ReadyToTrip中统计的总请求次数
	ReadyToTripForFailratio    float64       `json:"r2t_fail_ratio"`    //ReadyToTrip中统计的出错比率
}

type CliConfig

type CliConfig struct {
	DialAddress string        `json:"dial_address"`
	DialPort    int           `json:"dial_port"`
	DialScheme  string        `json:"dial_scheme"`
	Env         string        `json:"env"`
	LbType      string        `json:lbtype`
	Timeout     time.Duration `json:"timeout"`
}

type ClientRetryConfig

type ClientRetryConfig struct {
	On             bool          `json:"on-off"`
	Maxretry       int           `json:"max_retry"`          //客户端的最大重试次数
	PerCallTimeout time.Duration `json:"per_call_timeout"`   //每次RPC请求单独设置超时时间
	HeaderSign     bool          `json:"inject_header_sign"` //是否注入header字段
}

type Config

type Config struct {
	*viper.Viper
}

func NeedUse

func NeedUse(key string) *Config

需要使用,如果不存在则抛panic

func Use

func Use(key string) *Config

使用配置对象

func (*Config) MustBool

func (c *Config) MustBool(key string, defaultValue bool) bool

func (*Config) MustDuration

func (c *Config) MustDuration(key string, defaultValue time.Duration) time.Duration

func (*Config) MustFloat64

func (c *Config) MustFloat64(key string, defaultValue float64) float64

func (*Config) MustInt

func (c *Config) MustInt(key string, defaultValue int) int

func (*Config) MustInt64

func (c *Config) MustInt64(key string, defaultValue int64) int64

func (*Config) MustString

func (c *Config) MustString(key string, defaultValue string) string

func (*Config) MustStringMap

func (c *Config) MustStringMap(key string, defaultValue map[string]interface{}) map[string]interface{}

func (*Config) MustStringMapString

func (c *Config) MustStringMapString(key string, defaultValue map[string]string) map[string]string

func (*Config) MustStringSlice

func (c *Config) MustStringSlice(key string, defaultValue []string) []string

func (*Config) MustUint64

func (c *Config) MustUint64(key string, defaultValue uint64) uint64

func (*Config) NeedUse

func (c *Config) NeedUse(key string) *Config

func (*Config) Use

func (c *Config) Use(key string) *Config

type EtcdConfig

type EtcdConfig struct {
	Endpoints      []string      `json:"endpoints"`
	ConnectTimeout time.Duration `json:"timeout"`
	Secure         bool          `json:"secure"`
	TTL            int           `json:"ttl"`

	//Etcd
	DialKeepAliveTime    time.Duration `json:"dialkeepalivetime"`
	DialKeepAliveTimeout time.Duration `json:"dialkeepalivetimeout"`

	//ETCD 认证参数
	CertFilePath string `json:"certfilepath"`
	KeyFilePath  string `json:"keyfilepath"`
	CaCertPath   string `json:"cacertpath"`
	BasicAuth    bool   `json:"basicauth"`
	UserName     string `json:"username"`
	Password     string `json:"passwd"`
}

type LimiterConfig

type LimiterConfig struct {
	On          bool   `json:"on-off"`
	LimiterType string `json:"type"`
	LimiterRate int    `json:"rate"`
	LimiterSize int    `json:"bucketsize"`
}

type LogConfig

type LogConfig struct {
	//Level      string `json:"level"`
	FileName   string  `json:"file_name"`
	MaxSize    int     `json:"max_size"`
	MaxBackups int     `json:"max_backups"`
	MaxAge     int     `json:"max_age"`
	Compress   bool    `json:"compress"`
	Sampling   float64 `json:"sampling"`
}

type OnConfigChange

type OnConfigChange func(name string, op uint32)

type RegistryConfig

type RegistryConfig struct {
	RegOn               bool          `json:"on-off"`
	RegisterType        string        `json:"reg_type"`
	RegisterEndpoints   string        `json:"reg_endpoint"`
	RegisterTTL         time.Duration `json:"reg_ttl"`
	RegisterAPIOn       bool          `json:"reg_api_on"`
	RegisterRootPath    string        `json:"reg_root_path"`
	RegisterService     string        `json:"reg_service_name"`
	RegisterServiceVer  string        `json:"reg_service_version"`
	RegisterServiceAddr string        `json:"reg_service_addr"`
}

type SrvConfig

type SrvConfig struct {
	Addr              string        `json:"address"`
	Keepalive         bool          `json:"keepalive"`
	Timeout           time.Duration `json:"timeout"`
	IdleTimeout       time.Duration `json:"idle_timeout"`
	MaxLifeTime       time.Duration `json:"max_life"`
	ForceCloseWait    time.Duration `json:"close_wait"`
	KeepAliveInterval time.Duration `json:"keepalive_interval"`
	KeepAliveTimeout  time.Duration `json:"keepalive_timeout"`
	MaxRetry          int           `json:"max_retry"`
}

type SrvDnsConfig

type SrvDnsConfig struct {
	SrvName string `json:"name"`
	SrvPort int    `json:"port"`
}

type SysCollectorConfig

type SysCollectorConfig struct {
	Cputype           string        `json:"type"` //cvm or docker
	CollectorDuration time.Duration `json:"duration"`
	Multiply          int           `json:"multiply"` //cpu采集结果放大倍数
}

type TlsConfig

type TlsConfig struct {
	TLSon         bool   `json:"on-off"`
	TlsCommonName string `json:"cert_name"` //服务端证书name
	TLSCert       string `json:"tls_cert"`
	TLSKey        string `json:"tls_key"`
	TLSCaCert     string `json:"tls_ca_cert"`
}

type TracingConfig

type TracingConfig struct {
	ServiceName string `json:"service_name"`
	Collector   string `json:"collector"` //收集地址
	TracerType  string `json:"type"`
}

type WeightConfig

type WeightConfig struct {
	Weight string `json:"init_weight"`
}

Jump to

Keyboard shortcuts

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