-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
38 lines (27 loc) · 695 Bytes
/
main.go
File metadata and controls
38 lines (27 loc) · 695 Bytes
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
package main
import (
"fmt"
"github.com/xeipuuv/gojsonschema"
)
type User struct {
Email string `json:"email,omitempty"`
}
func main() {
var user = User{
Email: "asd.asd.asdf@gmail.com",
}
goLoader := gojsonschema.NewGoLoader(user)
//log.Println(goLoader)
schemaDoc := gojsonschema.NewReferenceLoader("file:///Users/a/go/src/awesomeProject/schema.json")
schema, _ := gojsonschema.NewSchema(schemaDoc)
//log.Println(schema)
result, _ := schema.Validate(goLoader)
if result.Valid() {
fmt.Printf("The document is valid\n")
} else {
fmt.Printf("The document is not valid. see errors :\n")
for _, desc := range result.Errors() {
fmt.Printf("- %s\n", desc)
}
}
}