forked from coreos/fleet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
62 lines (51 loc) · 1.43 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
package config
import (
"flag"
"io/ioutil"
"log"
"os"
"strconv"
"strings"
"github.com/coreos/fleet/third_party/github.com/coreos/go-etcd/etcd"
"github.com/coreos/fleet/third_party/github.com/golang/glog"
)
type Config struct {
EtcdServers []string
EtcdKeyPrefix string
PublicIP string
Verbosity int
RawMetadata string
AgentTTL string
VerifyUnits bool
AuthorizedKeysFile string
}
func (c *Config) Metadata() map[string]string {
meta := make(map[string]string, 0)
for _, pair := range strings.Split(c.RawMetadata, ",") {
parts := strings.SplitN(pair, "=", 2)
if len(parts) != 2 {
continue
}
key := strings.TrimSpace(parts[0])
val := strings.TrimSpace(parts[1])
meta[key] = val
}
return meta
}
// UpdateLoggingFlagsFromConfig extracts the logging-related options from
// the provided config and sets flags in the given flagset
func UpdateLoggingFlagsFromConfig(flagset *flag.FlagSet, conf *Config) {
err := flagset.Lookup("v").Value.Set(strconv.Itoa(conf.Verbosity))
if err != nil {
glog.Errorf("Failed to apply config.Verbosity to flag.v: %v", err)
}
err = flagset.Lookup("logtostderr").Value.Set("true")
if err != nil {
glog.Errorf("Failed to set flag.logtostderr to true: %v", err)
}
if conf.Verbosity > 2 {
etcd.SetLogger(log.New(os.Stdout, "go-etcd", log.LstdFlags))
} else {
etcd.SetLogger(log.New(ioutil.Discard, "go-etcd", log.LstdFlags))
}
}