/
config.go
49 lines (40 loc) · 1.06 KB
/
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
44
45
46
47
48
49
package nsq
import (
"fmt"
"time"
"github.com/JieTrancender/nsq_consumer/libconsumer/common"
)
type Config struct {
Nsqd string `config:"nsqd"`
Topic string `config:"topic"`
BulkMaxSize int `config:"bulk_max_size"`
MaxRetries int `config:"max_retries"`
WriteTimeout time.Duration `config:"write_timeout"`
DialTimeout time.Duration `config:"dial_timeout"`
// If not enabled topic, while using original topic
EnabledTopic bool `config:"enabled_topic"`
}
func defaultConfig() Config {
return Config{
Nsqd: "127.0.0.1:4150",
Topic: "nsq_consumer",
BulkMaxSize: 256,
MaxRetries: 3,
WriteTimeout: 6 * time.Second,
DialTimeout: 6 * time.Second,
EnabledTopic: false,
}
}
func readConfig(cfg *common.Config) (*Config, error) {
c := defaultConfig()
if err := cfg.Unpack(&c); err != nil {
return nil, err
}
return &c, nil
}
func (c *Config) Validate() error {
if c.EnabledTopic && c.Topic == "" {
return fmt.Errorf("Topic can not be empty when enabled topic")
}
return nil
}