added comments on functions and structs

This commit is contained in:
Paul 2019-06-05 23:03:40 +02:00
parent fe30f624be
commit e9ace8576d
2 changed files with 12 additions and 3 deletions

View File

@ -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(

View File

@ -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