|
|
@ -2,14 +2,24 @@ package cmd |
|
|
|
|
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"io/ioutil" |
|
|
|
"os" |
|
|
|
|
|
|
|
"github.com/FreifunkBremen/yanic/database" |
|
|
|
"github.com/FreifunkBremen/yanic/respond" |
|
|
|
"github.com/FreifunkBremen/yanic/runtime" |
|
|
|
"github.com/FreifunkBremen/yanic/runtime/config" |
|
|
|
"github.com/FreifunkBremen/yanic/webserver" |
|
|
|
"github.com/naoina/toml" |
|
|
|
) |
|
|
|
|
|
|
|
// Config represents the whole configuration
|
|
|
|
type Config struct { |
|
|
|
Respondd respond.Config |
|
|
|
Webserver webserver.Config |
|
|
|
Nodes runtime.NodesConfig |
|
|
|
Database database.Config |
|
|
|
} |
|
|
|
|
|
|
|
var ( |
|
|
|
configPath string |
|
|
|
collector *respond.Collector |
|
|
@ -17,11 +27,28 @@ var ( |
|
|
|
nodes *runtime.Nodes |
|
|
|
) |
|
|
|
|
|
|
|
func loadConfig() *config.Config { |
|
|
|
config, err := config.ReadConfigFile(configPath) |
|
|
|
func loadConfig() *Config { |
|
|
|
config, err := ReadConfigFile(configPath) |
|
|
|
if err != nil { |
|
|
|
fmt.Fprintln(os.Stderr, "unable to load config file:", err) |
|
|
|
os.Exit(2) |
|
|
|
} |
|
|
|
return config |
|
|
|
} |
|
|
|
|
|
|
|
// ReadConfigFile reads a config model from path of a yml file
|
|
|
|
func ReadConfigFile(path string) (config *Config, err error) { |
|
|
|
config = &Config{} |
|
|
|
|
|
|
|
file, err := ioutil.ReadFile(path) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
err = toml.Unmarshal(file, config) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
return |
|
|
|
} |