Skip to content
Snippets Groups Projects
Commit 932307d5 authored by Marius Nersveen's avatar Marius Nersveen
Browse files

Storing the filepath of the CSV file in a variable

parent 89d30367
No related branches found
No related tags found
No related merge requests found
package handlers
import (
"Assignment02/utils"
"encoding/csv"
"fmt"
"net/http"
......@@ -16,7 +17,7 @@ func HandleGetRequestForCurrentPercentage(w http.ResponseWriter, r *http.Request
//countryName := URLParts[??]
// Open the CSV file
fd, err := os.Open("renewable-share-energy.csv")
fd, err := os.Open(utils.CsvFilePath)
if err != nil {
fmt.Println("Error opening CSV file.")
fmt.Println(err)
......
......@@ -6,3 +6,4 @@ const CURRENT_PATH = "/energy/v1/renewables/current/"
const HISTORY_PATH = "/energy/v1/renewables/history/"
const NOTIFICATIONS_PATH = "/energy/v1/notifications/"
const STATUS_PATH = "/energy/v1/status/"
const CSV_FILE_PATH = "utils/renewable-share-energy.csv"
package utils
import (
"fmt"
"path/filepath"
)
func getCSVFilepath() string {
absPath, err := filepath.Abs(CSV_FILE_PATH)
if err != nil {
fmt.Println("Error getting absolute path:", err)
}
return absPath
}
var CsvFilePath = getCSVFilepath()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment