confs

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

This package contains popular things configuration and new methods for them

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFastHttpClient

func NewFastHttpClient(hcConf *FastHttpClientConf, customizer FastHttpClientCustomizer) *fasthttp.Client
Example
hcConf := &FastHttpClientConf{}
conf.Load(hcConf, "")
customizer := func(hc *fasthttp.Client) {
	// do something
}
hc := NewFastHttpClient(hcConf, customizer)
hc.Get(make([]byte, 0), "https://baidu.com")
Output:

func NewMySqlDb

func NewMySqlDb(conf *MysqlConf, customizer MysqlConfigCustomizer) *sql.DB
Example
mysqlConf := &MysqlConf{}
conf.Load(mysqlConf, "")
customizer := func(mc *mysql.Config) {
	mc.Params["autocommit"] = "true"
	mc.Params["charset"] = "utf8"
}
mySqlDb := NewMySqlDb(mysqlConf, customizer)
mySqlDb.Close()
Output:

func NewRedisClient

func NewRedisClient(rc *RedisConf, customizer RedisOptionCustomizer) *redis.Client
Example
redisConf := &RedisConf{}
conf.Load(redisConf, "")
customizer := func(ropt *redis.Options) {
	ropt.MaxRetries = 2
}
redisClient := NewRedisClient(redisConf, customizer)
redisClient.Close()
Output:

Types

type FastHttpClientConf

type FastHttpClientConf struct {
	CertChain     string // Path to cert when communicate client auth enabled origin server, including intermediate certs. x.509 pem encoded.
	PrivateKey    string // Path to private key when communicate client auth enabled origin server, including intermediate certs. PKCS #1 pem encoded.
	SslTrustMode  string // Trust mode when verifying server certificates. Available modes are OS: use host root CA set. INSECURE: do not verify. CUSTOM: verify by custom cert.
	SslTrustCerts string // Path to certificates that clients use when verifying server certificates, only useful when client-ssl-trust-mode set to CUSTOM. X.509 PEM encoded

	ReadTimeout         time.Duration
	WriteTimeout        time.Duration
	MaxConnDuration     time.Duration
	MaxConnsPerHost     int
	MaxIdleConnDuration time.Duration
	MaxConnWaitTimeout  time.Duration
}

Config keys:

| Environment            |  Flag                   |  Description                              |
|------------------------|-------------------------|-------------------------------------------|
| CERT_CHAIN             | -cert-chain             | Path to cert when communicate client auth |
|                        |                         | enabled origin server, including          |
|                        |                         | intermediate certs. x.509 pem encoded.    |
| PRIVATE_KEY            | -private-key            | Path to private key when communicate      |
|                        |                         | client auth enabled origin server,        |
|                        |                         | including intermediate certs.             |
|                        |                         | PKCS #1 pem encoded.                      |
| SSL_TRUST_MODE         | -ssl-trust-mode         | Trust mode when verifying server          |
|                        |                         | certificates. Available modes are:        |
|                        |                         | OS: use host root CA set.                 |
|                        |                         | INSECURE: do not verify.                  |
|                        |                         | CUSTOM: verify by custom cert.            |
| SSL_TRUST_CERTS        | -ssl-trust-certs        | Path to certificates that clients use     |
|                        |                         | when verifying server certificates, only  |
|                        |                         | useful when client-ssl-trust-mode set     |
|                        |                         | to CUSTOM. X.509 PEM encoded              |
| READ_TIMEOUT           | -read-timeout           |                                           |
| WRITE_TIMEOUT          | -write-timeout          |                                           |
| MAX_CONN_DURATION      | -max-conn-duration      |                                           |
| MAX_CONNS_PER_HOST     | -max-conns-per-host     |                                           |
| MAX_IDLE_CONN_DURATION | -max-idle-conn-duration |                                           |
| MAX_CONN_WAIT_TIMEOUT  | -max-conn-wait-timeout  |                                           |

Note: if FastHttpClientConf is nested in another struct, add corresponding prefix.

func (*FastHttpClientConf) String

func (c *FastHttpClientConf) String() string

type FastHttpClientCustomizer

type FastHttpClientCustomizer func(hc *fasthttp.Client)

type MysqlConf

type MysqlConf struct {
	Host     string // MySQL host
	Port     int    // MySQL port
	Username string // MySQL username
	Password string // MySQL password
	Database string // MySQL database

	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime time.Duration

	ReadTimeout  time.Duration
	WriteTimeout time.Duration
	Timeout      time.Duration

	Loc       string // Location for time.Time values
	ParseTime bool   // Parse time values to time.Time

	Params string
}

Config keys:

| Environment       |  Flag              |  Description                                               |
|-------------------|--------------------|------------------------------------------------------------|
| HOST              | -host              |                                                            |
| PORT              | -port              |                                                            |
| USERNAME          | -username          |                                                            |
| PASSWORD          | -password          |                                                            |
| DATABASE          | -database          |                                                            |
| MAX_OPEN_CONNS    | -max-open-conns    | Maximum number of open connections to the database.        |
|                   |                    | If == 0 means unlimited                                    |
| MAX_IDLE_CONNS    | -max-idle-conns    | Maximum number of connections in the idle connection pool. |
|                   |                    | If == 0 no idle connections are retained                   |
| CONN_MAX_LIFETIME | -conn-max-lifetime | Maximum amount of time a connection may be reused.         |
|                   |                    | If == 0, connections are reused forever.                   |
| LOC               | -loc               | Sets the location for time.Time values                     |
|                   |                    | (when using parseTime=true)                                |
|                   |                    | "Local" sets the system's location.                        |
|                   |                    | See time.LoadLocation for details.                         |
| PARSE_TIME        | -parse-time        | parseTime=true changes the output type of DATE and         |
|                   |                    | DATETIME values to time.Time instead of []byte / string    |
| READ_TIMEOUT      | -read-timeout      | I/O read timeout                                           |
| WRITE_TIMEOUT     | -write-timeout     | I/O write timeout                                          |
| TIMEOUT           | -timeout           | Timeout for establishing connections, aka dial timeout.    |
| PARAMS            |                    | Connection parameters, eg, foo=1&bar=%20                   |
|                   |                    | 1. All string values should be quoted with '               |
|                   |                    | 2. All value in PARAMS should be url.QueryEscaped          |
|                   |                    | more details:                                              |
|                   |                    | https://github.com/go-sql-driver/mysql#system-variables    |

Note: if MysqlConf is nested in another struct, add corresponding prefix.

more details: https://github.com/go-sql-driver/mysql

more details:

func (*MysqlConf) String

func (m *MysqlConf) String() string

type MysqlConfigCustomizer

type MysqlConfigCustomizer func(mc *mysql.Config)

type RedisConf

type RedisConf struct {
	Host     string // Redis host
	Port     int    // Redis port
	Password string // Redis password
	Pool     int    // Redis pool size
	MinIdle  int    // Redis min idle
}

Config keys:

| Environment   |  Flag     |  Description             |
|---------------|-----------|--------------------------|
| HOST          | -host     |                          |
| PORT          | -port     |                          |
| PASSWORD      | -password |                          |
| POOL          | -pool     | Connection pool size     |
| MIN_IDLE      | -min-idle | Minimal idle connections |

Note: if RedisConf is nested in another struct, add corresponding prefix.

func (*RedisConf) String

func (r *RedisConf) String() string

type RedisOptionCustomizer

type RedisOptionCustomizer func(ropt *redis.Options)

Jump to

Keyboard shortcuts

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