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/utils/test.go

29 lines
533 B
Go
Raw Permalink Normal View History

2024-07-11 11:10:30 +00:00
package utils
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
}