forked from nytimes/gizmo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
34 lines (28 loc) · 899 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package kafka
import (
"strings"
"github.com/NYTimes/gizmo/config"
)
// Config holds the basic information for working with Kafka.
type Config struct {
BrokerHosts []string
// BrokerHostsString is used when loading the list from environment variables.
// If loaded via the LoadEnvConfig() func, BrokerHosts will get updated with these
// values.
BrokerHostsString string `envconfig:"KAFKA_BROKER_HOSTS"`
Partition int32 `envconfig:"KAFKA_PARTITION"`
Topic string `envconfig:"KAFKA_TOPIC"`
MaxRetry int `envconfig:"KAFKA_MAX_RETRY"`
}
// LoadConfigFromEnv will attempt to load an Kafka object
// from environment variables. If not populated, nil
// is returned.
func LoadConfigFromEnv() *Config {
var kafka Config
config.LoadEnvConfig(&kafka)
if kafka.BrokerHostsString == "" {
return nil
}
kafka.BrokerHosts = strings.Split(kafka.BrokerHostsString, ",")
return &kafka
}