Skip to content

Commit 2958bf2

Browse files
committed
Make all config structs suitable for config.FromEnv()
1 parent 16856c0 commit 2958bf2

File tree

5 files changed

+33
-33
lines changed

5 files changed

+33
-33
lines changed

config/tls.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99

1010
// TLS provides TLS configuration options.
1111
type TLS struct {
12-
Enable bool `yaml:"tls"`
13-
Cert string `yaml:"cert"`
14-
Key string `yaml:"key"`
15-
Ca string `yaml:"ca"`
16-
Insecure bool `yaml:"insecure"`
12+
Enable bool `yaml:"tls" env:"TLS"`
13+
Cert string `yaml:"cert" env:"CERT"`
14+
Key string `yaml:"key" env:"KEY"`
15+
Ca string `yaml:"ca" env:"CA"`
16+
Insecure bool `yaml:"insecure" env:"INSECURE"`
1717
}
1818

1919
// MakeConfig assembles a tls.Config from t and serverName.

database/config.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import (
77

88
// Config defines database client configuration.
99
type Config struct {
10-
Type string `yaml:"type" default:"mysql"`
11-
Host string `yaml:"host"`
12-
Port int `yaml:"port"`
13-
Database string `yaml:"database"`
14-
User string `yaml:"user"`
15-
Password string `yaml:"password"`
10+
Type string `yaml:"type" env:"TYPE" default:"mysql"`
11+
Host string `yaml:"host" env:"HOST"`
12+
Port int `yaml:"port" env:"PORT"`
13+
Database string `yaml:"database" env:"DATABASE"`
14+
User string `yaml:"user" env:"USER"`
15+
Password string `yaml:"password" env:"PASSWORD,unset"`
1616
TlsOptions config.TLS `yaml:",inline"`
17-
Options Options `yaml:"options"`
17+
Options Options `yaml:"options" envPrefix:"OPTIONS_"`
1818
}
1919

2020
// Validate checks constraints in the supplied database configuration and returns an error if they are violated.

database/db.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,29 @@ type DB struct {
4646
// Options define user configurable database options.
4747
type Options struct {
4848
// Maximum number of open connections to the database.
49-
MaxConnections int `yaml:"max_connections" default:"16"`
49+
MaxConnections int `yaml:"max_connections" env:"MAX_CONNECTIONS" default:"16"`
5050

5151
// Maximum number of connections per table,
5252
// regardless of what the connection is actually doing,
5353
// e.g. INSERT, UPDATE, DELETE.
54-
MaxConnectionsPerTable int `yaml:"max_connections_per_table" default:"8"`
54+
MaxConnectionsPerTable int `yaml:"max_connections_per_table" env:"MAX_CONNECTIONS_PER_TABLE" default:"8"`
5555

5656
// MaxPlaceholdersPerStatement defines the maximum number of placeholders in an
5757
// INSERT, UPDATE or DELETE statement. Theoretically, MySQL can handle up to 2^16-1 placeholders,
5858
// but this increases the execution time of queries and thus reduces the number of queries
5959
// that can be executed in parallel in a given time.
6060
// The default is 2^13, which in our tests showed the best performance in terms of execution time and parallelism.
61-
MaxPlaceholdersPerStatement int `yaml:"max_placeholders_per_statement" default:"8192"`
61+
MaxPlaceholdersPerStatement int `yaml:"max_placeholders_per_statement" env:"MAX_PLACEHOLDERS_PER_STATEMENT" default:"8192"`
6262

6363
// MaxRowsPerTransaction defines the maximum number of rows per transaction.
6464
// The default is 2^13, which in our tests showed the best performance in terms of execution time and parallelism.
65-
MaxRowsPerTransaction int `yaml:"max_rows_per_transaction" default:"8192"`
65+
MaxRowsPerTransaction int `yaml:"max_rows_per_transaction" env:"MAX_ROWS_PER_TRANSACTION" default:"8192"`
6666

6767
// WsrepSyncWait enforces Galera cluster nodes to perform strict cluster-wide causality checks
6868
// before executing specific SQL queries determined by the number you provided.
6969
// Please refer to the below link for a detailed description.
7070
// https://icinga.com/docs/icinga-db/latest/doc/03-Configuration/#galera-cluster
71-
WsrepSyncWait int `yaml:"wsrep_sync_wait" default:"7"`
71+
WsrepSyncWait int `yaml:"wsrep_sync_wait" env:"WSREP_SYNC_WAIT" default:"7"`
7272
}
7373

7474
// Validate checks constraints in the supplied database options and returns an error if they are violated.

logging/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ type Options map[string]zapcore.Level
1414
// Config defines Logger configuration.
1515
type Config struct {
1616
// zapcore.Level at 0 is for info level.
17-
Level zapcore.Level `yaml:"level" default:"0"`
18-
Output string `yaml:"output"`
17+
Level zapcore.Level `yaml:"level" env:"LEVEL" default:"0"`
18+
Output string `yaml:"output" env:"OUTPUT"`
1919
// Interval for periodic logging.
20-
Interval time.Duration `yaml:"interval" default:"20s"`
20+
Interval time.Duration `yaml:"interval" env:"INTERVAL" default:"20s"`
2121

22-
Options `yaml:"options"`
22+
Options `yaml:"options" env:"OPTIONS"`
2323
}
2424

2525
// Validate checks constraints in the configuration and returns an error if they are violated.

redis/config.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import (
88

99
// Options define user configurable Redis options.
1010
type Options struct {
11-
BlockTimeout time.Duration `yaml:"block_timeout" default:"1s"`
12-
HMGetCount int `yaml:"hmget_count" default:"4096"`
13-
HScanCount int `yaml:"hscan_count" default:"4096"`
14-
MaxHMGetConnections int `yaml:"max_hmget_connections" default:"8"`
15-
Timeout time.Duration `yaml:"timeout" default:"30s"`
16-
XReadCount int `yaml:"xread_count" default:"4096"`
11+
BlockTimeout time.Duration `yaml:"block_timeout" env:"BLOCK_TIMEOUT" default:"1s"`
12+
HMGetCount int `yaml:"hmget_count" env:"HMGET_COUNT" default:"4096"`
13+
HScanCount int `yaml:"hscan_count" env:"HSCAN_COUNT" default:"4096"`
14+
MaxHMGetConnections int `yaml:"max_hmget_connections" env:"MAX_HMGET_CONNECTIONS" default:"8"`
15+
Timeout time.Duration `yaml:"timeout" env:"TIMEOUT" default:"30s"`
16+
XReadCount int `yaml:"xread_count" env:"XREAD_COUNT" default:"4096"`
1717
}
1818

1919
// Validate checks constraints in the supplied Redis options and returns an error if they are violated.
@@ -42,13 +42,13 @@ func (o *Options) Validate() error {
4242

4343
// Config defines Config client configuration.
4444
type Config struct {
45-
Host string `yaml:"host"`
46-
Port int `yaml:"port"`
47-
Username string `yaml:"username"`
48-
Password string `yaml:"password"`
49-
Database int `yaml:"database" default:"0"`
45+
Host string `yaml:"host" env:"HOST"`
46+
Port int `yaml:"port" env:"PORT"`
47+
Username string `yaml:"username" env:"USERNAME"`
48+
Password string `yaml:"password" env:"PASSWORD,unset"`
49+
Database int `yaml:"database" env:"DATABASE" default:"0"`
5050
TlsOptions config.TLS `yaml:",inline"`
51-
Options Options `yaml:"options"`
51+
Options Options `yaml:"options" envPrefix:"OPTIONS_"`
5252
}
5353

5454
// Validate checks constraints in the supplied Config configuration and returns an error if they are violated.

0 commit comments

Comments
 (0)