updated default values for configuration

This commit is contained in:
Paul 2019-07-19 20:23:05 +02:00
parent 0ed528c6ef
commit 5745ca3437
2 changed files with 19 additions and 13 deletions

View File

@ -2,6 +2,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"errors"
"flag" "flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
@ -25,27 +26,33 @@ func GetConfig(configfile string, weatherconfig *WeatherConfig) error {
var wc WeatherConfig var wc WeatherConfig
weatherSection := config.Section("weather") weatherSection := config.Section("weather")
wc.WeatherVersion = weatherSection.Key("version").String()
wc.WeatherAppID = weatherSection.Key("appid").String()
wc.WeatherCities = weatherSection.Key("cities").Strings(",")
wc.WeatherMeasurements = weatherSection.Key("measurements").Strings(",")
wc.WeatherTable = weatherSection.Key("table").String()
influxdbSection := config.Section("influxdb") wc.WeatherVersion = weatherSection.Key("version").MustString("2.5")
wc.InfluxHost = influxdbSection.Key("hostname").String() wc.WeatherAppID = weatherSection.Key("appid").MustString("appid")
wc.InfluxPort, err = influxdbSection.Key("port").Int() wc.WeatherCities = weatherSection.Key("cities").Strings(",")
if err != nil { if len(wc.WeatherCities) < 1 {
err := errors.New("No cities provided in config")
return err return err
} }
wc.InfluxUser = influxdbSection.Key("username").String() wc.WeatherMeasurements = weatherSection.Key("measurements").Strings(",")
wc.InfluxPass = influxdbSection.Key("password").String() if len(wc.WeatherMeasurements) < 1 {
wc.InfluxDB = influxdbSection.Key("database").String() err := errors.New("No measurements provided in config")
return err
}
influxdbSection := config.Section("influxdb")
wc.InfluxHost = influxdbSection.Key("hostname").MustString("localhost")
wc.InfluxPort = influxdbSection.Key("port").MustInt(8086)
wc.InfluxUser = influxdbSection.Key("username").MustString("username")
wc.InfluxPass = influxdbSection.Key("password").MustString("password")
wc.InfluxDB = influxdbSection.Key("database").MustString("me")
*weatherconfig = wc *weatherconfig = wc
return err return err
} }
// FetchData fetch data from api
func FetchData(city string) (Data, error) { func FetchData(city string) (Data, error) {
var d Data var d Data

View File

@ -6,7 +6,6 @@ type WeatherConfig struct {
WeatherAppID string WeatherAppID string
WeatherCities []string WeatherCities []string
WeatherMeasurements []string WeatherMeasurements []string
WeatherTable string
InfluxHost string InfluxHost string
InfluxPort int InfluxPort int
InfluxUser string InfluxUser string