33 lines
698 B
Go
33 lines
698 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/xeipuuv/gojsonschema"
|
|
"os"
|
|
|
|
"path/filepath"
|
|
)
|
|
|
|
func main() {
|
|
ex, err := os.Executable()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
exPath := filepath.Dir(ex)
|
|
schemaLoader := gojsonschema.NewReferenceLoader(fmt.Sprintf("file://%s/schema.json", exPath))
|
|
documentLoader := gojsonschema.NewReferenceLoader(fmt.Sprintf("file://%s/vars.json", exPath))
|
|
|
|
result, err := gojsonschema.Validate(schemaLoader, documentLoader)
|
|
if err != nil {
|
|
panic(err.Error())
|
|
}
|
|
|
|
if result.Valid() {
|
|
fmt.Println("The document is valid")
|
|
} else {
|
|
fmt.Println("The document is not valid. see errors:")
|
|
for _, desc := range result.Errors() {
|
|
fmt.Println("-", desc)
|
|
}
|
|
}
|
|
}
|