From e9ace8576d0504dc174e35e7729460705b527e26 Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Wed, 5 Jun 2019 23:03:40 +0200 Subject: [PATCH] added comments on functions and structs --- fuelprices.go | 7 +++++-- functions.go | 8 +++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/fuelprices.go b/fuelprices.go index 26dbc48..39cec40 100644 --- a/fuelprices.go +++ b/fuelprices.go @@ -17,10 +17,12 @@ type Srcfile struct { 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 @@ -35,8 +37,9 @@ type FuelPricesConfig struct { InfluxDB string } +// Price contains price of points of sale type Price struct { - Id string + ID string Fuel string Amount float64 } @@ -82,7 +85,7 @@ func main() { for _, p := range *prices { - tags := map[string]string{"pdv": p.Id, "fuel": p.Fuel} + tags := map[string]string{"pdv": p.ID, "fuel": p.Fuel} fields := map[string]interface{}{"value": p.Amount} point, _ := client.NewPoint( diff --git a/functions.go b/functions.go index 49d23c5..21aaf28 100644 --- a/functions.go +++ b/functions.go @@ -16,10 +16,12 @@ import ( "gopkg.in/ini.v1" ) +// ParseArgs is not yet implemented func ParseArgs() error { return nil } +// GetConfig fetch config from ini file func GetConfig(configfile string, fuelpricesconfig *FuelPricesConfig) error { flag.Usage = Usage flag.Parse() @@ -50,6 +52,7 @@ func GetConfig(configfile string, fuelpricesconfig *FuelPricesConfig) error { return err } +// DownloadFile fetch file from webserver func DownloadFile(url string) error { resp, err := http.Get(url) if err != nil { @@ -70,6 +73,7 @@ func DownloadFile(url string) error { return err } +// ExtractZip get the XML file to be processed func ExtractZip() error { zipfile, err = zip.NewReader(bytes.NewReader(szip.Content), int64(len(szip.Content))) @@ -92,6 +96,7 @@ func ExtractZip() error { return err } +// GetPrices parses the XML file and get values of prices func GetPrices(prices **[]Price, spos []string, stypes []string, sxpathbase string) error { var pr []Price @@ -111,7 +116,7 @@ func GetPrices(prices **[]Price, spos []string, stypes []string, sxpathbase stri if s, err := strconv.ParseFloat(i.Value, 64); err == nil { val = s } - pr = append(pr, Price{Id: station, Fuel: fuel, Amount: val}) + pr = append(pr, Price{ID: station, Fuel: fuel, Amount: val}) } } } @@ -120,6 +125,7 @@ func GetPrices(prices **[]Price, spos []string, stypes []string, sxpathbase stri return err } +// HandleError handles errors to return err func HandleError(err error) error { if err != nil { return err