From 72e5b16b7a710b20af08f68d0a90ac6580f890cf Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Tue, 13 Aug 2019 17:43:07 +0200 Subject: [PATCH] update error management, updated README --- README.md | 3 +++ functions.go | 12 ++++++------ weather.ini.sample | 1 - 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4743996..7d3b4b9 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,9 @@ measurements=temp,humidity,pressure ./weather -configfile weather.ini ``` +### TODO +- Yaml Config + ## License ```text Copyright (c) 2019, PaulBSD diff --git a/functions.go b/functions.go index 9b293df..cee7429 100644 --- a/functions.go +++ b/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) diff --git a/weather.ini.sample b/weather.ini.sample index ffad3d3..c6352bc 100644 --- a/weather.ini.sample +++ b/weather.ini.sample @@ -6,7 +6,6 @@ password=password database=database [weather] -version=2.5 appid=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx cities=Caen,Paris,Saint-Lo measurements=temp,humidity,pressure \ No newline at end of file