29 lines
509 B
Go
29 lines
509 B
Go
|
package endpoints
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
func loadJsonTestData[T any](testDataPath string) (T, error) {
|
||
|
// Create a variable to store the decoded JSON data
|
||
|
var jsonData T
|
||
|
|
||
|
// Open the JSON file
|
||
|
file, err := os.Open(testDataPath)
|
||
|
if err != nil {
|
||
|
return jsonData, err
|
||
|
}
|
||
|
defer file.Close()
|
||
|
|
||
|
// Create a decoder
|
||
|
decoder := json.NewDecoder(file)
|
||
|
|
||
|
// Decode the JSON data into the struct
|
||
|
if err := decoder.Decode(&jsonData); err != nil {
|
||
|
return jsonData, err
|
||
|
}
|
||
|
|
||
|
return jsonData, nil
|
||
|
}
|