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

View File

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