updated default values for configuration
This commit is contained in:
parent
0ed528c6ef
commit
5745ca3437
31
functions.go
31
functions.go
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user