This repository was archived by the owner on Mar 22, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -79,9 +79,9 @@ var err_statuscode error = fmt.Errorf("bad status code")
7979// This function fetches the current electricity price from "https://www.elprisetjustnu.se/elpris-api", then prosess it and updates globalPrice
8080func getAPIPriceData (apiURL string ) error {
8181 //Validate the URL//
82- parsedURL , err := url .Parse (apiURL ) // ensures the string is a valid UTL , .schema and .Host checks prevent emty or altered URL
82+ parsedURL , err := url .Parse (apiURL ) // ensures the string is a valid URL , .schema and .Host checks prevent emty or altered URL
8383 if err != nil || parsedURL .Scheme == "" || parsedURL .Host == "" {
84- return errors .New ("invalid URL" )
84+ return errors .New ("The URL is invalid " )
8585 }
8686 // end of validating the URL//
8787 res , err := http .Get (parsedURL .String ())
@@ -94,9 +94,14 @@ func getAPIPriceData(apiURL string) error {
9494 return err
9595 }
9696
97- var data []GlobalPriceData // Create a list to hold the gateway json
97+ var data []GlobalPriceData // Create a list to hold the data json
9898 err = json .Unmarshal (body , & data ) // "unpack" body from []byte to []GlobalPriceData, save errors
99- res .Body .Close () // defer res.Body.Close()
99+ /*
100+ if err != nil {
101+ return err
102+ }
103+ */
104+ defer res .Body .Close () // defer res.Body.Close()
100105
101106 if res .StatusCode > 299 {
102107 return err_statuscode
You can’t perform that action at this time.
0 commit comments