2017-07-29 14:11:50 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/BurntSushi/toml"
|
2017-07-30 02:54:43 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
defaultListenAddr = ":8080"
|
|
|
|
defaultSocketPath = "/var/run/element.sock"
|
2017-07-29 14:11:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ParseConfig returns a Config object from a raw string config TOML
|
|
|
|
func ParseConfig(data string) (*Config, error) {
|
|
|
|
var cfg Config
|
|
|
|
if _, err := toml.Decode(data, &cfg); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-07-30 02:54:43 +00:00
|
|
|
if cfg.ListenAddr == "" {
|
|
|
|
logrus.Warnf("using default listen addr: %s", defaultListenAddr)
|
|
|
|
cfg.ListenAddr = defaultListenAddr
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.SocketPath == "" {
|
|
|
|
logrus.Warnf("using default socket path: %s", defaultSocketPath)
|
|
|
|
cfg.SocketPath = defaultSocketPath
|
|
|
|
}
|
|
|
|
|
2017-07-29 14:11:50 +00:00
|
|
|
return &cfg, nil
|
|
|
|
}
|