confs

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 24 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 NewEsClient added in v0.9.0

func NewEsClient(conf *EsConf, customizer EsConfigCustomizer) *elasticsearch.Client

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 NewFasthttpRoutingPprofHandler added in v0.10.0

func NewFasthttpRoutingPprofHandler(conf *PprofConf) routing.Handler

create a fasthttp routing handler for pprof handler

Example
pprofConf := &PprofConf{
	Username:             "abc",
	Password:             "xyz",
	BlockProfileRate:     1,
	MutexProfileFraction: 1,
}
router := routing.New()
router.Any("/debug/pprof/*", NewFasthttpRoutingPprofHandler(pprofConf))
Output:

func NewGinPprofBasicAuthFilter added in v0.10.0

func NewGinPprofBasicAuthFilter(conf *PprofConf) gin.HandlerFunc

create a gin basic auth filter for pprof endpoint

Example
pprofConf := &PprofConf{
	Username:             "abc",
	Password:             "xyz",
	BlockProfileRate:     1,
	MutexProfileFraction: 1,
}
r := gin.Default()
pprofGroup := r.Group("debug/pprof", NewGinPprofBasicAuthFilter(pprofConf))
pprof.RouteRegister(pprofGroup, "")
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 NewMySqlDbWithTracer added in v0.17.0

func NewMySqlDbWithTracer(conf *MysqlConf, tracer *go2sky.Tracer, customizer MysqlConfigCustomizer) *sql.DB

func NewOracleDb added in v0.18.0

func NewOracleDb(conf *OracleConf, customizer OracleUrlOptionsCustomizer) *sql.DB

func NewOracleDbWithTracer added in v0.18.0

func NewOracleDbWithTracer(conf *OracleConf, tracer *go2sky.Tracer, customizer OracleUrlOptionsCustomizer) *sql.DB

func NewPostgresqlDb added in v0.20.0

func NewPostgresqlDb(conf *PostgresqlConf, customizer PostgresqlUrlOptionsCustomizer) *sql.DB

func NewPostgresqlDbWithTracer added in v0.20.0

func NewPostgresqlDbWithTracer(conf *PostgresqlConf, tracer *go2sky.Tracer, customizer PostgresqlUrlOptionsCustomizer) *sql.DB

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 EsConf added in v0.9.0

type EsConf struct {
	Addrs               string
	Username            string
	Password            string
	MaxConnsPerHost     int
	MaxIdleConnsPerHost int
}

func (*EsConf) String added in v0.9.0

func (m *EsConf) String() string

type EsConfigCustomizer added in v0.9.0

type EsConfigCustomizer func(mc *elasticsearch.Config)

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

func (*MysqlConf) String

func (m *MysqlConf) String() string

type MysqlConfigCustomizer

type MysqlConfigCustomizer func(mc *mysql.Config)

type OracleConf added in v0.18.0

type OracleConf struct {
	Host           string // Oracle host
	Port           int    // Oracle port
	Username       string // Oracle username
	Password       string // Oracle password
	Service        string // Oracle service
	Sid            string // or Oracle SID
	Servers        string // Add more servers (nodes) in case of RAC in form of "srv1:port,srv2:port
	ConnectTimeout int    // Connection timeout seconds
	Params         string

	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime time.Duration
}

Config keys:

| Environment       |  Flag              |  Description                                               |
|-------------------|--------------------|------------------------------------------------------------|
| HOST              | -host              |                                                            |
| PORT              | -port              |                                                            |
| USERNAME          | -username          |                                                            |
| PASSWORD          | -password          |                                                            |
| SERVICE           | -service           | Oracle service name                                        |
| SID               | -sid               | Oracle SID, you need to provide either service or sid option  |
| SERVERS           | -servers           | Add more servers (nodes) in case of RAC in form of "srv1:port,srv2:port  |
| CONNECT_TIMEOUT   | -connect-timeout   | Connection timeout seconds.                                |
| 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/sijms/go-ora                            |
| 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.                   |
|                   |                    | (when using parseTime=true)                                |
|                   |                    | "Local" sets the system's location.                        |
|                   |                    | See time.LoadLocation for details.                         |

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

more details: https://github.com/sijms/go-ora

func (*OracleConf) String added in v0.18.0

func (c *OracleConf) String() string

type OracleUrlOptionsCustomizer added in v0.18.0

type OracleUrlOptionsCustomizer func(options map[string]string)

type PostgresqlConf added in v0.20.0

type PostgresqlConf struct {
	Host           string // Postgresql host
	Port           int    // Postgresql port
	Username       string // Postgresql username
	Password       string // Postgresql password
	Database       string // Postgresql database
	ConnectTimeout int    // Connection timeout seconds
	Params         string

	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime time.Duration
}

Config keys:

| Environment       |  Flag              |  Description                                               |
|-------------------|--------------------|------------------------------------------------------------|
| HOST              | -host              |                                                            |
| PORT              | -port              |                                                            |
| USERNAME          | -username          |                                                            |
| PASSWORD          | -password          |                                                            |
| CONNECT_TIMEOUT   | -connect-timeout   | Connection timeout seconds.                                |
| 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/sijms/go-ora                            |
| 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.                   |
|                   |                    | (when using parseTime=true)                                |
|                   |                    | "Local" sets the system's location.                        |
|                   |                    | See time.LoadLocation for details.                         |

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

more details: https://pkg.go.dev/github.com/lib/pq

https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING-URIS

func (*PostgresqlConf) String added in v0.20.0

func (c *PostgresqlConf) String() string

type PostgresqlUrlOptionsCustomizer added in v0.20.0

type PostgresqlUrlOptionsCustomizer func(options map[string]string)

type PprofConf added in v0.10.0

type PprofConf struct {
	Username             string // /debug/pprof/* basic auth username
	Password             string // /debug/pprof/* basic auth password
	BlockProfileRate     int
	MutexProfileFraction int
}

func (*PprofConf) String added in v0.10.0

func (p *PprofConf) String() string

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
	Db       int    // Database to be selected after connecting to the server. See https://redis.io/commands/select
}

Config keys:

| Environment   |  Flag     |  Description             |
|---------------|-----------|--------------------------|
| HOST          | -host     |                          |
| PORT          | -port     |                          |
| PASSWORD      | -password |                          |
| POOL          | -pool     | Connection pool size     |
| MIN_IDLE      | -min-idle | Minimal idle connections |
| DB            | -db       | Database to be selected after connecting to the server. |

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