conf

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: MIT Imports: 8 Imported by: 1

README

Read this in other languages: English, 中文.

conf

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Conf = Config{}
)

Functions

func Ext

func Ext(keys string, defVal ...interface{}) interface{}

func ExtBool

func ExtBool(keys string, defVal ...interface{}) bool

ExtBool is a shorcut for (c *Config) ExtBool()

func ExtDuration

func ExtDuration(keys string, defVal ...interface{}) time.Duration

ExtDuration is a shorcut for (c *Config) ExtDuration()

func ExtFloat32

func ExtFloat32(keys string, defVal ...interface{}) float32

ExtFloat32 is a shorcut for (c *Config) ExtFloat32()

func ExtFloat64

func ExtFloat64(keys string, defVal ...interface{}) float64

ExtFloat64 is a shorcut for (c *Config) ExtFloat64()

func ExtInt

func ExtInt(keys string, defVal ...interface{}) int

ExtInt is a shorcut for (c *Config) ExtInt()

func ExtInt16

func ExtInt16(keys string, defVal ...interface{}) int16

ExtInt16 is a shorcut for (c *Config) ExtInt16()

func ExtInt32

func ExtInt32(keys string, defVal ...interface{}) int32

ExtInt32 is a shorcut for (c *Config) ExtInt32()

func ExtInt64

func ExtInt64(keys string, defVal ...interface{}) int64

ExtInt64 is a shorcut for (c *Config) ExtInt64()

func ExtInt8

func ExtInt8(keys string, defVal ...interface{}) int8

ExtInt8 is a shorcut for (c *Config) ExtInt8()

func ExtString

func ExtString(keys string, defVal ...interface{}) string

ExtString is a shorcut for (c *Config) ExtString()

func LoadConf

func LoadConf(path string)

Types

type Config

type Config struct {
	Log             Log                    `yaml:"log,flow"`
	Mongos          []*Mongo               `yaml:"mongos,flow"`
	Elasticsearches []*Elasticsearch       `yaml:"elasticsearches,flow"`
	Redises         []*Redis               `yaml:"redises,flow"`
	KafkaProducers  []*KafkaProducer       `yaml:"kafkaProducers,flow"`
	KafkaConsumers  []*KafkaConsumer       `yaml:"kafkaConsumers,flow"`
	EXT             map[string]interface{} `yaml:"ext,flow"`
}

func (*Config) Ext

func (c *Config) Ext(keys string, defaultVal ...interface{}) interface{}

Ext will return the value of the EXT config, the keys is a string separated by DOT(.). If you provide a default value, this method will return the it while the key cannot be found. otherwise it will raise a panic!

func (*Config) ExtBool

func (c *Config) ExtBool(keys string, defaultVal ...interface{}) bool

func (*Config) ExtDuration

func (c *Config) ExtDuration(keys string, defaultVal ...interface{}) time.Duration

func (*Config) ExtFloat32

func (c *Config) ExtFloat32(keys string, defaultVal ...interface{}) float32

func (*Config) ExtFloat64

func (c *Config) ExtFloat64(keys string, defaultVal ...interface{}) float64

func (*Config) ExtInt

func (c *Config) ExtInt(keys string, defaultVal ...interface{}) int

func (*Config) ExtInt16

func (c *Config) ExtInt16(keys string, defaultVal ...interface{}) int16

func (*Config) ExtInt32

func (c *Config) ExtInt32(keys string, defaultVal ...interface{}) int32

func (*Config) ExtInt64

func (c *Config) ExtInt64(keys string, defaultVal ...interface{}) int64

func (*Config) ExtInt8

func (c *Config) ExtInt8(keys string, defaultVal ...interface{}) int8

func (*Config) ExtSep

func (c *Config) ExtSep(keys, sep string) (interface{}, error)

Ext will return the value of the EXT config, the keys is separated by the given sep string.

func (*Config) ExtString

func (c *Config) ExtString(keys string, defaultVal ...interface{}) string

type DBSsh added in v1.1.0

type DBSsh struct {
	On      bool   `yaml:"on"`
	Address string `yaml:"address"` //ip:port
	User    string `yaml:"user"`    //ssh user
	PriKey  string `yaml:"priKey"`  //base64
	KeyPass string `yaml:"keyPass"` //key password
}

type Database

type Database struct {
	Key      string                 `yaml:"key"`
	Addrs    []string               `yaml:"addrs,flow"`
	User     string                 `yaml:"user"`
	Password string                 `yaml:"password"`
	DBName   string                 `yaml:"dbName"`
	EXT      map[string]interface{} `yaml:",flow"`
}

func (*Database) Ext

func (d *Database) Ext(key string, defaultVal ...interface{}) interface{}

Get value of given key of Database section.

func (*Database) ExtBool

func (d *Database) ExtBool(key string, defaultVal ...interface{}) bool

func (*Database) ExtDuration

func (d *Database) ExtDuration(key string, defaultVal ...interface{}) time.Duration

func (*Database) ExtInt

func (d *Database) ExtInt(key string, defaultVal ...interface{}) int

func (*Database) ExtString

func (d *Database) ExtString(key string, defaultVal ...interface{}) string

type Elasticsearch added in v1.1.0

type Elasticsearch struct {
	Database    `yaml:",inline"`
	Type        string `yaml:"type"`
	MaxPoolSize int    `yaml:"maxPoolSize"`
}

type KafkaConsumer

type KafkaConsumer struct {
	Key          string        `yaml:"key"`
	Address      []string      `yaml:"address"` // kafka地址
	Group        string        `yaml:"group"`   // groupId
	Offset       int64         `yaml:"offset"`
	Ack          int           `yaml:"ack"`          // ack类型
	DialTimeout  time.Duration `yaml:"dialTimeout"`  // How long to wait for the initial connection.
	ReadTimeout  time.Duration `yaml:"readTimeout"`  // How long to wait for a response.
	WriteTimeout time.Duration `yaml:"writeTimeout"` // How long to wait for a transmit.
	KeepAlive    time.Duration `yaml:"keepAlive"`
	//username and password for SASL/PLAIN  or SASL/SCRAM authentication
	User     string `yaml:"user"`
	Password string `yaml:"password"`
}

type KafkaProducer

type KafkaProducer struct {
	Key           string   `yaml:"key"`
	Address       []string `yaml:"address"`
	Async         bool     `yaml:"async"`
	ReturnSuccess bool     `yaml:"returnSuccess"`
	ReturnError   bool     `yaml:"returnError"`
	//username and password for SASL/PLAIN  or SASL/SCRAM authentication
	User     string `yaml:"user"`
	Password string `yaml:"password"`
}

type Log

type Log struct {
	lumberjack.Logger `yaml:",inline"`
	LogLevel          string `yaml:"logLevel"`
	Stdout            bool   `yaml:"stdout"`
	FileOut           bool   `yaml:"fileOut"`
	HttpOut           bool   `yaml:"httpOut"`
	OutputEncoder     string `yaml:"outputEncoder"`  // 编码器配置,json:NewJSONEncoder,console:NewConsoleEncoder。默认是console
	ContentEncoder    string `yaml:"contentEncoder"` // 内容编码器,默认utf-8, 还支持gbk,bg18030,等等...
	HttpUrl           string `yaml:"httpUrl"`        // 请求地址
	HttpDebug         bool   `yaml:"httpDebug"`      // 是否打印请求输出成功和失败的情况
	HttpTimeout       int    `yaml:"httpTimeout"`    // httpclient超时
}

type Mongo added in v1.1.0

type Mongo struct {
	Database   `yaml:",inline"`
	AuthSource string `yaml:"authSource"`

	// 连接管理
	Direct         bool          `yaml:"direct"`
	ConnectTimeout time.Duration `yaml:"connectTimeout"` //连接超时. 默认为10秒
	Keepalive      time.Duration `yaml:"keepalive"`      //DialInfo.DialServer实现
	WriteTimeout   time.Duration `yaml:"writeTimeout"`   //写超时, 默认为ConnectTimeout
	ReadTimeout    time.Duration `yaml:"readTimeout"`    //读超时, 默认为ConnectTimeout
	Compressors    []string      `yaml:"compressors,flow"`

	// 连接池管理
	MinPoolSize       int `yaml:"minPoolSize"`       //对应DialInfo.MinPoolSize
	MaxPoolSize       int `yaml:"maxPoolSize"`       //对应DialInfo.PoolLimit
	MaxPoolWaitTimeMS int `yaml:"maxPoolWaitTimeMS"` //对应DialInfo.PoolTimeout获取连接超时, 默认为0永不超时
	MaxPoolIdleTimeMS int `yaml:"maxPoolIdleTimeMS"` //对应DialInfo.MaxIdleTimeMS

	//读写偏好
	Mode string     `yaml:"mode"`
	Safe *MongoSafe `yaml:"safe"`

	//ssh tune(experimental)
	Ssh *DBSsh `yaml:"ssh"`
}

type MongoSafe added in v1.1.0

type MongoSafe struct {
	W        int    `yaml:"w"`        // Min # of servers to ack before success
	WMode    string `yaml:"wMode"`    // Write mode for MongoDB 2.0+ (e.g. "majority")
	RMode    string `yaml:"rMode"`    // Read mode for MonogDB 3.2+ ("majority", "local", "linearizable")
	WTimeout int    `yaml:"wTimeout"` // Milliseconds to wait for W before timing out
	FSync    bool   `yaml:"fSync"`    // Sync via the journal if present, or via data files sync otherwise
	J        bool   `yaml:"j"`        // Sync via the journal if present
}

type Redis

type Redis struct {
	Key              string   `yaml:"key"`
	MasterName       string   `yaml:"masterName"`
	Addrs            []string `yaml:"addrs,flow"`
	Db               int      `yaml:"db"`
	PoolSize         int      `yaml:"poolSize"`
	Password         string   `yaml:"password"`
	SentinelPassword string   `yaml:"sentinelPassword"`
	DialTimeout      string   `yaml:"dialTimeout"`
	ReadTimeout      string   `yaml:"readTimeout"`
	WriteTimeout     string   `yaml:"writeTimeout"`
	IdleTimeout      string   `yaml:"idleTimeout"`
	ReadOnly         bool     `yaml:"readOnly"`
	RouteByLatency   bool     `yaml:"routeByLatency"`
	RouteRandomly    bool     `yaml:"routeRandomly"`
}

Jump to

Keyboard shortcuts

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