-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource.go
41 lines (34 loc) · 823 Bytes
/
resource.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"log"
"github.com/xeipuuv/gojsonschema"
)
// Resource contains test data and schema
type Resource struct {
Schema string `json:"schema"`
Data []string `json:"data"`
}
// ResourceResult contains validation results
type ResourceResult struct {
*gojsonschema.Result
URL string
Schema string
}
// Check validates resource by its schema
func (r Resource) Check(wd string, ch chan *ResourceResult) {
schema := r.Schema
schemaLoader := gojsonschema.NewReferenceLoader("file://" + wd + "/" + schema)
for _, url := range r.Data {
result, err := gojsonschema.Validate(schemaLoader, gojsonschema.NewReferenceLoader(url))
if err != nil {
log.Printf("Error (%s; %s): %s\n", schema, url, err)
continue
}
ch <- &ResourceResult{
result,
url,
schema,
}
}
close(ch)
}