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 Content []byte
} }
// Outfile is the output XML file
type Outfile struct { type Outfile struct {
Content []byte Content []byte
} }
// FuelPricesConfig is the main configuration
type FuelPricesConfig struct { type FuelPricesConfig struct {
RemoteURL string RemoteURL string
RemoteFilename string RemoteFilename string
@ -35,8 +37,9 @@ type FuelPricesConfig struct {
InfluxDB string InfluxDB string
} }
// Price contains price of points of sale
type Price struct { type Price struct {
Id string ID string
Fuel string Fuel string
Amount float64 Amount float64
} }
@ -82,7 +85,7 @@ func main() {
for _, p := range *prices { 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} fields := map[string]interface{}{"value": p.Amount}
point, _ := client.NewPoint( point, _ := client.NewPoint(

View File

@ -16,10 +16,12 @@ import (
"gopkg.in/ini.v1" "gopkg.in/ini.v1"
) )
// ParseArgs is not yet implemented
func ParseArgs() error { func ParseArgs() error {
return nil return nil
} }
// GetConfig fetch config from ini file
func GetConfig(configfile string, fuelpricesconfig *FuelPricesConfig) error { func GetConfig(configfile string, fuelpricesconfig *FuelPricesConfig) error {
flag.Usage = Usage flag.Usage = Usage
flag.Parse() flag.Parse()
@ -50,6 +52,7 @@ func GetConfig(configfile string, fuelpricesconfig *FuelPricesConfig) error {
return err return err
} }
// DownloadFile fetch file from webserver
func DownloadFile(url string) error { func DownloadFile(url string) error {
resp, err := http.Get(url) resp, err := http.Get(url)
if err != nil { if err != nil {
@ -70,6 +73,7 @@ func DownloadFile(url string) error {
return err return err
} }
// ExtractZip get the XML file to be processed
func ExtractZip() error { func ExtractZip() error {
zipfile, err = zip.NewReader(bytes.NewReader(szip.Content), int64(len(szip.Content))) zipfile, err = zip.NewReader(bytes.NewReader(szip.Content), int64(len(szip.Content)))
@ -92,6 +96,7 @@ func ExtractZip() error {
return err return err
} }
// GetPrices parses the XML file and get values of prices
func GetPrices(prices **[]Price, spos []string, stypes []string, sxpathbase string) error { func GetPrices(prices **[]Price, spos []string, stypes []string, sxpathbase string) error {
var pr []Price 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 { if s, err := strconv.ParseFloat(i.Value, 64); err == nil {
val = s 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 return err
} }
// HandleError handles errors to return err
func HandleError(err error) error { func HandleError(err error) error {
if err != nil { if err != nil {
return err return err