use json files to store data/ get css to work
This commit is contained in:
41
internal/store/experience_store_json.go
Normal file
41
internal/store/experience_store_json.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
type ExperienceJSON struct {
|
||||
ID int `json:"id"`
|
||||
Company string `json:"company"`
|
||||
EmployeeType string `json:"employeeType"`
|
||||
Position string `json:"position"`
|
||||
Tasks []string `json:"tasks"`
|
||||
Tools string `json:"tools"`
|
||||
Years int `json:"years"`
|
||||
}
|
||||
|
||||
func GetAllExperiencesJSON() ([]ExperienceJSON, error) {
|
||||
jsonFile, err := os.Open("data/experience.json")
|
||||
if err != nil {
|
||||
fmt.Println("File not found; Error: ", err.Error())
|
||||
}
|
||||
|
||||
defer jsonFile.Close()
|
||||
|
||||
byteValue, err := io.ReadAll(jsonFile)
|
||||
if err != nil {
|
||||
fmt.Println("Unable to read json file; Error: ", err.Error())
|
||||
}
|
||||
|
||||
var experience []ExperienceJSON
|
||||
|
||||
err = json.Unmarshal(byteValue, &experience)
|
||||
if err != nil {
|
||||
fmt.Println("Unable to unmarshal; Error: ", err.Error())
|
||||
}
|
||||
|
||||
return experience, nil
|
||||
}
|
||||
Reference in New Issue
Block a user