changed configuration with default parameters

This commit is contained in:
Paul 2019-07-20 14:49:14 +02:00
parent 237f7a2907
commit f702827034

View File

@ -3,6 +3,7 @@ package main
import ( import (
"archive/zip" "archive/zip"
"bytes" "bytes"
"errors"
"flag" "flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
@ -35,21 +36,27 @@ func GetConfig(configfile string, fuelpricesconfig *FuelPricesConfig) error {
var fpc FuelPricesConfig var fpc FuelPricesConfig
fuelpricesSection := config.Section("fuelprices") fuelpricesSection := config.Section("fuelprices")
fpc.RemoteURL = fuelpricesSection.Key("remote_url").String() fpc.RemoteURL = fuelpricesSection.Key("remote_url").MustString("https://donnees.roulez-eco.fr/opendata/instantane")
fpc.RemoteFilename = fuelpricesSection.Key("remote_filename").String() fpc.RemoteFilename = fuelpricesSection.Key("remote_filename").MustString("PrixCarburants_instantane.xml")
fpc.XPathBase = fuelpricesSection.Key("xpath_base").String() fpc.XPathBase = fuelpricesSection.Key("xpath_base").MustString(".//pdv[@id='%s']/prix[@nom='%s']")
fpc.Table = fuelpricesSection.Key("table").String() fpc.Table = fuelpricesSection.Key("table").MustString("fuel_price")
fpc.Pos = fuelpricesSection.Key("pos").Strings(",")
if len(fpc.Pos) < 1 {
err := errors.New("No pos defined")
return err
}
fpc.Types = fuelpricesSection.Key("types").Strings(",")
if len(fpc.Types) < 1 {
err := errors.New("No fuel types defined")
return err
}
influxdbSection := config.Section("influxdb") influxdbSection := config.Section("influxdb")
fpc.InfluxHost = influxdbSection.Key("hostname").String() fpc.InfluxHost = influxdbSection.Key("hostname").MustString("localhost")
fpc.InfluxPort, err = influxdbSection.Key("port").Int() fpc.InfluxPort = influxdbSection.Key("port").MustInt(8086)
fpc.InfluxUser = influxdbSection.Key("username").String() fpc.InfluxUser = influxdbSection.Key("username").MustString("username")
fpc.InfluxPass = influxdbSection.Key("password").String() fpc.InfluxPass = influxdbSection.Key("password").MustString("password")
fpc.InfluxDB = influxdbSection.Key("database").MustString("me")
fpc.InfluxDB = influxdbSection.Key("database").String()
fpc.Pos = fuelpricesSection.Key("pos").Strings(",")
fpc.Types = fuelpricesSection.Key("types").Strings(",")
*fuelpricesconfig = fpc *fuelpricesconfig = fpc