added units config variable

This commit is contained in:
Paul 2020-02-16 11:44:27 +01:00
parent eddbf0bc90
commit b8e1331a78
4 changed files with 6 additions and 2 deletions

View File

@ -25,6 +25,7 @@ database=database
appid=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
cities=Caen|Paris|Saint-Lo
measurements=temp|humidity|pressure
units=metric
```
### Run

View File

@ -20,6 +20,7 @@ func GetConfig(config *Config, configfile string) error {
weatherSection := cfg.Section("weather")
config.WeatherAppID = weatherSection.Key("appid").MustString("appid")
config.WeatherUnits = weatherSection.Key("units").MustString("")
config.WeatherCities = weatherSection.Key("cities").Strings("|")
if len(config.WeatherCities) < 1 {
return fmt.Errorf("No cities provided in config")
@ -33,7 +34,7 @@ func GetConfig(config *Config, configfile string) error {
config.InfluxURL = influxdbSection.Key("url").MustString("http://localhost:8086")
config.InfluxUser = influxdbSection.Key("username").MustString("username")
config.InfluxPass = influxdbSection.Key("password").MustString("password")
config.InfluxDB = influxdbSection.Key("database").MustString("me")
config.InfluxDB = influxdbSection.Key("database").MustString("database")
return err
}
@ -41,6 +42,7 @@ func GetConfig(config *Config, configfile string) error {
// Config is the main configuration
type Config struct {
WeatherAppID string
WeatherUnits string
WeatherCities []string
WeatherMeasurements []string
InfluxURL string

View File

@ -22,7 +22,7 @@ func FetchData(c *config.Config, city string) (Data, error) {
DisableCompression: false,
}}
q := fmt.Sprintf("https://api.openweathermap.org/data/2.5/weather?q=%s&appid=%s&units=metric", city, c.WeatherAppID)
q := fmt.Sprintf("https://api.openweathermap.org/data/2.5/weather?q=%s&appid=%s&units=%s", city, c.WeatherAppID, c.WeatherUnits)
r, err := httpClient.Get(q)
if err != nil {

View File

@ -8,3 +8,4 @@ database=database
appid=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
cities=Caen|Paris|Saint-Lo
measurements=temp|humidity|pressure
units=metric