-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.go
43 lines (34 loc) · 885 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
35
36
37
38
39
40
41
42
43
package kafka
import (
"flag"
"fmt"
)
type Config struct {
// General
Brokers []string `yaml:"brokers"`
ClientID string `yaml:"clientId"`
TLS TLSConfig `yaml:"tls"`
SASL SASLConfig `yaml:"sasl"`
TopicReplicationFactor int16 `yaml:"topicReplicationFactor"`
}
// RegisterFlags for all sensitive Kafka SASL configs.
func (c *Config) RegisterFlags(f *flag.FlagSet) {
c.TLS.RegisterFlags(f)
c.SASL.RegisterFlags(f)
}
func (c *Config) Validate() error {
if len(c.Brokers) == 0 {
return fmt.Errorf("you must configure at least one broker to connect to")
}
err := c.SASL.Validate()
if err != nil {
return fmt.Errorf("failed to validate SASL config: %w", err)
}
return nil
}
// SetDefaults for Kafka config
func (c *Config) SetDefaults() {
c.ClientID = "owl-shop"
c.TopicReplicationFactor = 3
c.SASL.SetDefaults()
}