xconf

package
v0.0.0-...-68aaea9 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppConfig

type AppConfig struct {
	Port    int   `json:",default=12301"`
	Timeout int64 `json:",default=15000"`
}

type Config

type Config struct {
	Gateway   GatewayConfig
	App       AppConfig
	Log       LogConfig
	Discovery DiscoveryConfig
	Mode      string `json:",default=pro,options=dev|test|rt|pre|pro"`
}

func (Config) AppRpcServerConf

func (c Config) AppRpcServerConf() zrpc.RpcServerConf

func (Config) Etcd

func (c Config) Etcd(name string) discov.EtcdConf

func (Config) GatewayRpcServerConf

func (c Config) GatewayRpcServerConf() zrpc.RpcServerConf

func (Config) LogConf

func (c Config) LogConf(name string) logx.LogConf

func (Config) NewAppRpc

func (c Config) NewAppRpc() appservice.AppService

type DiscoveryConfig

type DiscoveryConfig struct {
	// Etcd represents the etcd configurations. If not set, then use k8s.
	Etcd EtcdConf `json:",optional"`
	// K8sNamespace represents the k8s namespace, If not set, then use localhost.
	// If you want to use k8s, You have to create service for all rpc services in k8s.
	// The service name should be `${serviceName}-svc`, and the port name suggested to be `rpc`.
	// example: user-rpc-svc, tokengating-rpc-svc
	// And k8s deployment should set serviceAccount, which must have find-endpoint permission.
	K8sNamespace string `json:",optional"`
}

type EtcdConf

type EtcdConf struct {
	Hosts              []string
	KeyPrefix          string `json:",optional"`
	ID                 int64  `json:",optional"`
	User               string `json:",optional"`
	Pass               string `json:",optional"`
	CertFile           string `json:",optional"`
	CertKeyFile        string `json:",optional=CertFile"`
	CACertFile         string `json:",optional=CertFile"`
	InsecureSkipVerify bool   `json:",optional"`
}

type GatewayConfig

type GatewayConfig struct {
	Port    int   `json:",default=12301"`
	Timeout int64 `json:",default=15000"`
	Http    struct {
		Cors struct {
			Enable           bool     `json:",optional"`
			AllowOrigins     []string `json:",optional"`
			AllowHeaders     []string `json:",optional"`
			AllowMethods     []string `json:",optional"`
			ExposeHeaders    []string `json:",optional"`
			AllowCredentials bool     `json:",optional"`
		} `json:",optional"`
		ApiLog struct {
			Apis []string `json:",optional"` // 格式: GET r'^/api/v1/user/.*' 表示所有以 /api/v1/user/ 开头的 GET 请求都会被记录
		}
		Host string `json:",default=0.0.0.0"`
		Port int    `json:",default=12300"`
	}
	Websocket struct {
		KeepAliveTickerSecond int `json:",default=30"` // 定时器,每隔n秒检测连接是否存活
		KeepAliveSecond       int `json:",default=60"` // 检测是否存活时,如果超过n秒没有收到客户端的消息,则关闭连接
	}
}

type LogConfig

type LogConfig struct {
	// Mode represents the logging mode, default is `console`.
	// console: log to console.
	// file: log to file.
	// volume: used in k8s, prepend the hostname to the log file name.
	Mode string `json:",default=console,options=[console,file,volume]"`
	// Encoding represents the encoding type, default is `json`.
	// json: json encoding.
	// plain: plain text encoding, typically used in development.
	Encoding string `json:",default=json,options=[json,plain]"`
	// TimeFormat represents the time format, default is `2006-01-02T15:04:05.000Z07:00`.
	TimeFormat string `json:",optional"`
	// Path represents the log file path, default is `logs`.
	Path string `json:",default=logs"`
	// Level represents the log level, default is `info`.
	Level string `json:",default=info,options=[debug,info,error,severe]"`
	// MaxContentLength represents the max content bytes, default is no limit.
	MaxContentLength uint32 `json:",optional"`
	// Compress represents whether to compress the log file, default is `false`.
	Compress bool `json:",optional"`
	// Stat represents whether to log statistics, default is `true`.
	Stat bool `json:",default=true"`
	// KeepDays represents how many days the log files will be kept. Default to keep all files.
	// Only take effect when Mode is `file` or `volume`, both work when Rotation is `daily` or `size`.
	KeepDays int `json:",optional"`
	// StackCooldownMillis represents the cooldown time for stack logging, default is 100ms.
	StackCooldownMillis int `json:",default=100"`
	// MaxBackups represents how many backup log files will be kept. 0 means all files will be kept forever.
	// Only take effect when RotationRuleType is `size`.
	// Even thougth `MaxBackups` sets 0, log files will still be removed
	// if the `KeepDays` limitation is reached.
	MaxBackups int `json:",default=0"`
	// MaxSize represents how much space the writing log file takes up. 0 means no limit. The unit is `MB`.
	// Only take effect when RotationRuleType is `size`
	MaxSize int `json:",default=0"`
	// Rotation represents the type of log rotation rule. Default is `daily`.
	// daily: daily rotation.
	// size: size limited rotation.
	Rotation string `json:",default=daily,options=[daily,size]"`
}

Jump to

Keyboard shortcuts

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