Commit 6b4ab53d authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Cherrypick: Refactor for testability

parent c8c4af4b
......@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
......@@ -265,13 +266,8 @@ func (conf *Config) validateConfig() (err error) {
}
// ReadConfig reads a config file and validates it
func ReadConfig(configFile string) (conf *Config, err error) {
if configFile == "" {
return nil, fmt.Errorf("Please provide the --config flag. See --help")
}
log.Printf("[Conf] Reading config file %s", configFile)
configBytes, err := ioutil.ReadFile(configFile)
func ReadConfig(r io.Reader) (conf *Config, err error) {
configBytes, err := ioutil.ReadAll(r)
if err != nil {
return
}
......
......@@ -159,7 +159,16 @@ func main() {
}
// read the config file
conf, err := config.ReadConfig(*configFile)
if *configFile == "" {
log.Fatalf("[Conf] Please provide the --config flag. See --help")
}
log.Printf("[Conf] Opening config file %s", *configFile)
handle, err := os.Open(*configFile)
if err != nil {
log.Fatalf("[Conf] Error opening config file: %s", err)
}
conf, err := config.ReadConfig(handle)
if err != nil {
log.Fatalf("[Conf] %s", err)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment