conf

package
v1.19.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: MIT Imports: 14 Imported by: 0

README

CommonConfig 及各组件启动参数统一方案

  1. 都需要有--file加载启动参数的方式,文件格式为json
  2. 共有的参数保持一致,引用common/conf中的结构
  3. 不启用多余的,不需要的参数
  4. 各模块自定义的参数格式,小写+下划线
  5. 需要export成为flag的,tag格式为:json:"flag_name" short:"short_hand_of_flag" value:"default_value" usage:"flag_usage",其中json,value,usage为必须字段
  6. flag支持多级结构体嵌套
  7. flag支持IntSlice和StringSlice,默认值用逗号(,)分割,如 value:"a,b,c"
  8. 参数解析优先级:命令行 > 配置文件 > 默认值

参考例子(storage启动参数配置):

type StorageOptions struct {
    // 引用所需参数
    conf.FileConfig
    conf.ServiceConfig
    conf.MetricConfig
    conf.ZkConfig
    conf.ServerOnlyCertConfig

    // storage自定义参数
    DBConfig     string `json:"database_config_file" value:"storage-database.conf" usage:"Config file for database."`
}

func main() {
    op := &StorageOptions{}

    // 解析参数
    conf.Parse(op)
}

目前共有的参数包括

// Config file, if set it will cover all the flag value it contains
type FileConfig struct {
    ConfigFile string `json:"file" short:"f" value:"" usage:"json file with configuration"`
}

// Service bind
type ServiceConfig struct {
    Address string `json:"address" short:"a" value:"127.0.0.1" usage:"IP address to listen on for this service"`
    Port    uint   `json:"port" short:"p" value:"8080" usage:"Port to listen on for this service"`
}

// Local info
type LocalConfig struct {
    LocalIP string `json:"local_ip" value:"127.0.0.1" usage:"IP address of this host"`
}

// Metric info
type MetricConfig struct {
    MetricPort uint `json:"metric_port" value:"8081" usage:"Port to listen on for metric"`
}

// Register discover
type ZkConfig struct {
    BCSZk string `json:"bcs_zookeeper" value:"127.0.0.1:2181" usage:"Zookeeper server for registering and discovering"`
}

// Server and client TLS config, can not be import with ClientCertOnlyConfig or ServerCertOnlyConfig
type CertConfig struct {
    ServerCertDir  string `json:"server_cert_dir" value:"" usage:"Directory of server certificate. If set, it will looking for bcs-inner-server.crt/bcs-inner-server.key/bcs-inner-ca.crt and set up an HTTPS server"`
    ClientCertDir  string `json:"client_cert_dir" value:"" usage:"Directory of client certificate. If set, it will looking for bcs-inner-client.crt/bcs-inner-client.key/bcs-inner-ca.crt"`
    CAFile         string `json:"ca_file" value:"" usage:"CA file. If server_cert_file/server_key_file/ca_file are all set, it will set up an HTTPS server required and verified client cert"`
    ServerCertFile string `json:"server_cert_file" value:"" usage:"Server public key file(*.crt). If both server_cert_file and server_key_file are set, it will set up an HTTPS server"`
    ServerKeyFile  string `json:"server_key_file" value:"" usage:"Server private key file(*.key). If both server_cert_file and server_key_file are set, it will set up an HTTPS server"`
    ClientCertFile string `json:"client_cert_file" value:"" usage:"Client public key file(*.crt)."`
    ClientKeyFile  string `json:"client_key_file" value:"" usage:"Client private key file(*.key)."`
}

// Client TLS config, can not be import with CertConfig or ServerCertOnlyConfig
type ClientOnlyCertConfig struct {
    ClientCertDir  string `json:"client_cert_dir" value:"" usage:"Directory of client certificate. If set, it will looking for bcs-inner-client.crt/bcs-inner-client.key/bcs-inner-ca.crt"`
    CAFile         string `json:"ca_file" value:"" usage:"CA file. If server_cert_file/server_key_file/ca_file are all set, it will set up an HTTPS server required and verified client cert"`
    ClientCertFile string `json:"client_cert_file" value:"" usage:"Client public key file(*.crt)."`
    ClientKeyFile  string `json:"client_key_file" value:"" usage:"Client private key file(*.key)."`
}

// Server TLS config, can not be import with ClientCertOnlyConfig or CertConfig
type ServerOnlyCertConfig struct {
    ServerCertDir  string `json:"server_cert_dir" value:"" usage:"Directory of server certificate. If set, it will looking for bcs-inner-server.crt/bcs-inner-server.key/bcs-inner-ca.crt and set up an HTTPS server"`
    CAFile         string `json:"ca_file" value:"" usage:"CA file. If server_cert_file/server_key_file/ca_file are all set, it will set up an HTTPS server required and verified client cert"`
    ServerCertFile string `json:"server_cert_file" value:"" usage:"Server public key file(*.crt). If both server_cert_file and server_key_file are set, it will set up an HTTPS server"`
    ServerKeyFile  string `json:"server_key_file" value:"" usage:"Server private key file(*.key). If both server_cert_file and server_key_file are set, it will set up an HTTPS server"`
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(config interface{})

Parse parse all config item

Types

type CertConfig

type CertConfig struct {
	CAFile         string `` /* 185-byte string literal not displayed */
	ServerCertFile string `` /* 188-byte string literal not displayed */
	ServerKeyFile  string `` /* 187-byte string literal not displayed */
	ClientCertFile string `json:"client_cert_file" value:"" usage:"Client public key file(*.crt)" mapstructure:"client_cert_file"`
	ClientKeyFile  string `json:"client_key_file" value:"" usage:"Client private key file(*.key)" mapstructure:"client_key_file"`
}

CertConfig Server and client TLS config, can not be import with ClientCertOnlyConfig or ServerCertOnlyConfig

type ClientOnlyCertConfig

type ClientOnlyCertConfig struct {
	CAFile         string `` /* 162-byte string literal not displayed */
	ClientCertFile string `json:"client_cert_file" value:"" usage:"Client public key file(*.crt)"`
	ClientKeyFile  string `json:"client_key_file" value:"" usage:"Client private key file(*.key)"`
}

ClientOnlyCertConfig Client TLS config, can not be import with CertConfig or ServerCertOnlyConfig

type Config

type Config struct {
	Configmap map[string]string
	KeyList   []string
	// contains filtered or unexported fields
}

Config struct for configuration

func (*Config) InitConfig

func (c *Config) InitConfig(path string)

InitConfig init config by file path

func (Config) List

func (c Config) List(node string) map[string]string

List list all item by node

func (Config) Read

func (c Config) Read(node, key string) string

Read read config by key

type CustomCertConfig

type CustomCertConfig struct {
	CAFile         string `` /* 206-byte string literal not displayed */
	ServerCertFile string `` /* 209-byte string literal not displayed */
	ServerKeyFile  string `` /* 208-byte string literal not displayed */
	ServerKeyPwd   string `` /* 136-byte string literal not displayed */
	ClientCertFile string `` /* 155-byte string literal not displayed */
	ClientKeyFile  string `` /* 153-byte string literal not displayed */
	ClientKeyPwd   string `` /* 136-byte string literal not displayed */
}

type FileConfig

type FileConfig struct {
	ConfigFile string `json:"file" short:"f" value:"" usage:"json file with configuration"`
}

FileConfig Config file, if set it will cover all the flag value it contains

type LicenseServerConfig

type LicenseServerConfig struct {
	LSAddress        string `json:"ls_address" value:"" usage:"The license server address" mapstructure:"ls_address"`
	LSCAFile         string `json:"ls_ca_file" value:"" usage:"CA file for connecting to license server" mapstructure:"ls_ca_file"`
	LSClientCertFile string `` /* 141-byte string literal not displayed */
	LSClientKeyFile  string `` /* 140-byte string literal not displayed */
}

LicenseServerConfig License server config

type LocalConfig

type LocalConfig struct {
	LocalIP   string `json:"local_ip" value:"" usage:"IP address of this host" mapstructure:"local_ip"`
	LocalIPv6 string `json:"local_ipv6" value:"" usage:"IPv6 address of this host" mapstructure:"local_ipv6"`
}

LocalConfig Local info

type LogConfig

type LogConfig struct {
	LogDir     string `json:"log_dir" value:"./logs" usage:"If non-empty, write log files in this directory" mapstructure:"log_dir"`
	LogMaxSize uint64 `json:"log_max_size" value:"500" usage:"Max size (MB) per log file." mapstructure:"log_max_size"`
	LogMaxNum  int    `` /* 146-byte string literal not displayed */

	ToStdErr        bool   `json:"logtostderr" value:"false" usage:"log to standard error instead of files" mapstructure:"logtostderr"`
	AlsoToStdErr    bool   `json:"alsologtostderr" value:"false" usage:"log to standard error as well as files" mapstructure:"alsologtostderr"`
	Verbosity       int32  `json:"v" value:"0" usage:"log level for V logs" mapstructure:"v"`
	StdErrThreshold string `json:"stderrthreshold" value:"2" usage:"logs at or above this threshold go to stderr" mapstructure:"stderrthreshold"`
	VModule         string `json:"vmodule" value:"" usage:"comma-separated list of pattern=N settings for file-filtered logging" mapstructure:"vmodule"`
	TraceLocation   string `json:"log_backtrace_at" value:"" usage:"when logging hits line file:N, emit a stack trace" mapstructure:"log_backtrace_at"`
}

LogConfig Log configuration

type MetricConfig

type MetricConfig struct {
	MetricPort uint `json:"metric_port" value:"8081" usage:"Port to listen on for metric" mapstructure:"metric_port" `
}

MetricConfig Metric info

type ProcessConfig

type ProcessConfig struct {
	PidDir string `json:"pid_dir" value:"./pid" usage:"The dir for pid file" mapstructure:"pid_dir"`
}

ProcessConfig Process configuration

type ServerOnlyCertConfig

type ServerOnlyCertConfig struct {
	CAFile         string `` /* 162-byte string literal not displayed */
	ServerCertFile string `` /* 156-byte string literal not displayed */
	ServerKeyFile  string `` /* 156-byte string literal not displayed */
}

ServerOnlyCertConfig Server TLS config, can not be import with ClientCertOnlyConfig or CertConfig

type ServiceConfig

type ServiceConfig struct {
	Address         string `json:"address" short:"a" value:"127.0.0.1" usage:"IP address to listen on for this service" mapstructure:"address"`
	IPv6Address     string `json:"ipv6_address" value:"" usage:"IPv6 address to listen on for this service" mapstructure:"ipv6_address"`
	Port            uint   `json:"port" short:"p" value:"8080" usage:"Port to listen on for this service" mapstructure:"port"`
	InsecureAddress string `json:"insecure_address" value:"" usage:"insecure IP address to listen on for this service" mapstructure:"insecure_address"`
	InsecurePort    uint   `json:"insecure_port" value:"" usage:"insecure port to listen on for this service" mapstructure:"insecure_port"`
	ExternalIp      string `json:"external_ip" value:"" usage:"external IP address to listen on for this service" mapstructure:"external_ip"`
	ExternalIPv6    string `json:"external_ipv6" value:"" usage:"external IPv6 address to listen on for this service" mapstructure:"external_ipv6"`
	ExternalPort    uint   `json:"external_port" value:"" usage:"external port to listen on for this service" mapstructure:"external_port"`
}

ServiceConfig Service bind

type ZkConfig

type ZkConfig struct {
	BCSZk     string `` /* 130-byte string literal not displayed */
	BCSZKIPv6 string `` /* 139-byte string literal not displayed */
}

ZkConfig bcs zookeeper for service discovery

Jump to

Keyboard shortcuts

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