update error management, updated README
This commit is contained in:
parent
7176c0a968
commit
72e5b16b7a
@ -34,6 +34,9 @@ measurements=temp,humidity,pressure
|
||||
./weather -configfile weather.ini
|
||||
```
|
||||
|
||||
### TODO
|
||||
- Yaml Config
|
||||
|
||||
## License
|
||||
```text
|
||||
Copyright (c) 2019, PaulBSD
|
||||
|
12
functions.go
12
functions.go
@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
@ -30,13 +29,11 @@ func GetConfig(weatherconfig *WeatherConfig, configfile string) error {
|
||||
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
|
||||
return fmt.Errorf("No cities provided in config")
|
||||
}
|
||||
wc.WeatherMeasurements = weatherSection.Key("measurements").Strings(",")
|
||||
if len(wc.WeatherMeasurements) < 1 {
|
||||
err := errors.New("No measurements provided in config")
|
||||
return err
|
||||
return fmt.Errorf("No measurements provided in config")
|
||||
}
|
||||
|
||||
influxdbSection := config.Section("influxdb")
|
||||
@ -110,12 +107,15 @@ func SendToInflux(wc *WeatherConfig, d Data) error {
|
||||
tags := map[string]string{"city": d.City}
|
||||
fields := map[string]interface{}{"value": value}
|
||||
|
||||
point, _ := client.NewPoint(
|
||||
point, err := client.NewPoint(
|
||||
key,
|
||||
tags,
|
||||
fields,
|
||||
time.Now(),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
bp.AddPoint(point)
|
||||
err = httpClient.Write(bp)
|
||||
|
@ -6,7 +6,6 @@ password=password
|
||||
database=database
|
||||
|
||||
[weather]
|
||||
version=2.5
|
||||
appid=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
cities=Caen,Paris,Saint-Lo
|
||||
measurements=temp,humidity,pressure
|
Loading…
Reference in New Issue
Block a user