This repository has been archived by the owner on Sep 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
66 lines (56 loc) · 1.94 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"github.com/habx/service-logfwd/clients"
"github.com/habx/service-logfwd/clients/list"
"github.com/kelseyhightower/envconfig"
)
// Config is the main config
type Config struct {
ListenAddr string `envconfig:"LISTEN_ADDR"` // Listening address
LogEnv string `envconfig:"LOG_ENV"` // Logging environment: dev or prod
LogstashMaxEventSize int `envconfig:"LOGSTASH_EVENT_MAX_SIZE"` // Maximum size accepted for reading data in logstash
LogstashAuthPrefixToken string `envconfig:"LOGSTASH_AUTH_PREFIX_TOKEN"` // Logstash prefix auth token (logmatic format)
LogstashAuthKey string `envconfig:"LOGSTASH_AUTH_KEY"` // Logstash authentication key
LogstashAuthValue string `envconfig:"LOGSTASH_AUTH_VALUE"` // Logstash authentication value
OutputClientConfigs map[string]clients.Config
}
func NewConfig() *Config {
return &Config{
ListenAddr: ":5050",
LogstashMaxEventSize: 300 * 1024, // 300KB
LogEnv: "prod",
OutputClientConfigs: make(map[string]clients.Config),
}
}
func (c *Config) Load() error {
/*
if err := c.Scalyr.Load(); err != nil {
return fmt.Errorf("couldn't load scalyr config: %s", err)
}
*/
if err := envconfig.Process("", c); err != nil {
return fmt.Errorf("couldn't load config from env vars: %s", err)
}
if err := c.check(); err != nil {
return fmt.Errorf("config check issue: %s", err)
}
{
anOutputWasEnabled := false
for _, oc := range list.LIST {
conf := oc.Config()
if err := conf.Load(); err != nil {
return fmt.Errorf("couldn't load output client of %s: %s", oc.Name(), err)
}
anOutputWasEnabled = anOutputWasEnabled || conf.Enabled()
c.OutputClientConfigs[oc.Name()] = conf
}
if !anOutputWasEnabled {
return fmt.Errorf("at least one output client should be enabled")
}
}
return nil
}
func (c *Config) check() error {
return nil
}