This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
e621-sdk-go/pkg/e621/endpoints/utils_test.go
2023-10-24 16:28:24 +02:00

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
}