package util import ( "bytes" "encoding/json" "log" "os" "slices" "gitlab.hamburg.ccc.de/ccchh/spaceapid/types" ) // ParseTemplate parses the given file and func ParseTemplate(file string) (resp types.SpaceAPIResponseV14) { // Read template file template, err := os.ReadFile(file) if err != nil { log.Fatalln("Failed reading file:", err) } // Parse JSON dec := json.NewDecoder(bytes.NewReader(template)) dec.DisallowUnknownFields() err = dec.Decode(&resp) if err != nil { log.Fatalln("Could not parse SpaceAPI response template:", err) } // Check if compatible with v14 if !slices.Contains(resp.APICompatibility, "14") { log.Fatalln("Provided template doesn't specify compatibility with API version 14") } return }