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