diff --git a/fuelprices.go b/fuelprices.go index 833ffd8..3a652f5 100644 --- a/fuelprices.go +++ b/fuelprices.go @@ -10,40 +10,6 @@ import ( client "github.com/influxdata/influxdb1-client/v2" ) -// Srcfile source file -type Srcfile struct { - Filename string - Filepath string - Content []byte -} - -// Outfile is the output XML file -type Outfile struct { - Content []byte -} - -// FuelPricesConfig is the main configuration -type FuelPricesConfig struct { - RemoteURL string - RemoteFilename string - XPathBase string - Pos []string - Types []string - TmpDir string - InfluxHost string - InfluxPort int - InfluxUser string - InfluxPass string - InfluxDB string -} - -// Price contains price of points of sale -type Price struct { - ID string - Fuel string - Amount float64 -} - var szip Srcfile var sxml Srcfile var ofile Outfile @@ -88,7 +54,7 @@ func main() { fields := map[string]interface{}{"value": p.Amount} point, _ := client.NewPoint( - "fuel_price", + fpc.InfluxTable, tags, fields, now, diff --git a/functions.go b/functions.go index 9285f4b..a7d2a4b 100644 --- a/functions.go +++ b/functions.go @@ -10,7 +10,6 @@ import ( "net/http" "os" "strconv" - "strings" "github.com/antchfx/xmlquery" "gopkg.in/ini.v1" @@ -43,9 +42,10 @@ func GetConfig(configfile string, fuelpricesconfig *FuelPricesConfig) error { HandleError(err) fpc.InfluxDB = fuelpricesSection.Key("influx_db").String() + fpc.InfluxTable = fuelpricesSection.Key("influx_table").String() - fpc.Pos = strings.Split(fuelpricesSection.Key("pos").String(), ",") - fpc.Types = strings.Split(fuelpricesSection.Key("types").String(), ",") + fpc.Pos = fuelpricesSection.Key("pos").Strings(",") + fpc.Types = fuelpricesSection.Key("types").Strings(",") *fuelpricesconfig = fpc @@ -55,13 +55,13 @@ func GetConfig(configfile string, fuelpricesconfig *FuelPricesConfig) error { // DownloadFile fetch file from webserver func DownloadFile(url string) error { resp, err := http.Get(url) - HandleError(err) + HandleError(err) szip.Content, err = ioutil.ReadAll(resp.Body) - HandleError(err) + HandleError(err) err = resp.Body.Close() - HandleError(err) + HandleError(err) return err } @@ -136,7 +136,6 @@ func HandleFatalError(err error) { // Usage displays possible arguments func Usage() { - fmt.Fprintf(os.Stderr, "Usage: fuelprices [configfile]\n") flag.PrintDefaults() os.Exit(1) } diff --git a/types.go b/types.go new file mode 100644 index 0000000..02a154d --- /dev/null +++ b/types.go @@ -0,0 +1,36 @@ +package main + +// Srcfile source file +type Srcfile struct { + Filename string + Filepath string + Content []byte +} + +// Outfile is the output XML file +type Outfile struct { + Content []byte +} + +// FuelPricesConfig is the main configuration +type FuelPricesConfig struct { + RemoteURL string + RemoteFilename string + XPathBase string + Pos []string + Types []string + TmpDir string + InfluxHost string + InfluxPort int + InfluxUser string + InfluxPass string + InfluxDB string + InfluxTable string +} + +// Price contains price of points of sale +type Price struct { + ID string + Fuel string + Amount float64 +}