github.com/nextlinux/gosbom@v0.81.1-0.20230627115839-1ff50c281391/gosbom/formats/gosbomjson/validator.go (about) 1 package gosbomjson 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "io" 7 "strings" 8 9 "github.com/nextlinux/gosbom/gosbom/formats/gosbomjson/model" 10 ) 11 12 func validator(reader io.Reader) error { 13 type Document struct { 14 Schema model.Schema `json:"schema"` 15 } 16 17 dec := json.NewDecoder(reader) 18 19 var doc Document 20 err := dec.Decode(&doc) 21 if err != nil { 22 return fmt.Errorf("unable to decode: %w", err) 23 } 24 25 // note: we accept all schema versions 26 // TODO: add per-schema version parsing 27 if strings.Contains(doc.Schema.URL, "nextlinux/gosbom") { 28 return nil 29 } 30 return fmt.Errorf("could not extract gosbom schema") 31 }