From 0083207235a83dee663f32d139d6477460f5213d Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Sat, 15 Jun 2019 13:55:48 +0200 Subject: [PATCH] refactored config names --- common.ini.sample | 12 +++++++----- fuelprices.go | 2 +- functions.go | 14 ++++++++------ types.go | 3 +-- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/common.ini.sample b/common.ini.sample index 11b49d7..28fafc0 100644 --- a/common.ini.sample +++ b/common.ini.sample @@ -8,10 +8,12 @@ xpath_base=.//pdv[@id='%s']/prix[@nom='%s'] # Comma separated values for pos and types pos=50000007 types=Gazole,SP95,SP98 +table=fuel_price +[influxdb] # Influxdb settings -influx_host=host -influx_db=me -influx_port=8086 -influx_user=influx -influx_pass=password \ No newline at end of file +hostname=host +database=me +port=8086 +username=influx +password=password \ No newline at end of file diff --git a/fuelprices.go b/fuelprices.go index 3a652f5..08dd5c8 100644 --- a/fuelprices.go +++ b/fuelprices.go @@ -54,7 +54,7 @@ func main() { fields := map[string]interface{}{"value": p.Amount} point, _ := client.NewPoint( - fpc.InfluxTable, + fpc.Table, tags, fields, now, diff --git a/functions.go b/functions.go index 9e4c2a6..dc9e288 100644 --- a/functions.go +++ b/functions.go @@ -33,15 +33,17 @@ func GetConfig(configfile string, fuelpricesconfig *FuelPricesConfig) error { fpc.RemoteURL = fuelpricesSection.Key("remote_url").String() fpc.RemoteFilename = fuelpricesSection.Key("remote_filename").String() fpc.XPathBase = fuelpricesSection.Key("xpath_base").String() - fpc.InfluxHost = fuelpricesSection.Key("influx_host").String() - fpc.InfluxPort, err = fuelpricesSection.Key("influx_port").Int() + fpc.Table = fuelpricesSection.Key("table").String() + + influxdbSection := config.Section("influxdb") + fpc.InfluxHost = influxdbSection.Key("hostname").String() + fpc.InfluxPort, err = influxdbSection.Key("port").Int() HandleError(err) - fpc.InfluxUser = fuelpricesSection.Key("influx_user").String() - fpc.InfluxPass = fuelpricesSection.Key("influx_pass").String() + fpc.InfluxUser = influxdbSection.Key("username").String() + fpc.InfluxPass = influxdbSection.Key("password").String() HandleError(err) - fpc.InfluxDB = fuelpricesSection.Key("influx_db").String() - fpc.InfluxTable = fuelpricesSection.Key("influx_table").String() + fpc.InfluxDB = influxdbSection.Key("database").String() fpc.Pos = fuelpricesSection.Key("pos").Strings(",") fpc.Types = fuelpricesSection.Key("types").Strings(",") diff --git a/types.go b/types.go index 02a154d..5f7d59f 100644 --- a/types.go +++ b/types.go @@ -19,13 +19,12 @@ type FuelPricesConfig struct { XPathBase string Pos []string Types []string - TmpDir string + Table string InfluxHost string InfluxPort int InfluxUser string InfluxPass string InfluxDB string - InfluxTable string } // Price contains price of points of sale