Skip to content

Commit

Permalink
Merge pull request jsonresume#19 from ss22ever/master
Browse files Browse the repository at this point in the history
Create validator
  • Loading branch information
stp-ip committed Mar 15, 2018
2 parents 83920ab + f75503b commit 65fdb0a
Show file tree
Hide file tree
Showing 63 changed files with 4,241 additions and 496 deletions.
36 changes: 33 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions validator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"flag"
"fmt"
"log"
"os"
"path"

"github.com/gobuffalo/packr"
"github.com/xeipuuv/gojsonschema"
)

func main() {
var doc string
flag.StringVar(&doc, "doc", "examples/invalid/invalid_email.json", "Example file")
flag.Parse()
ValidateJSON(doc)
}

// ValidateJSON is used to check for validity
func ValidateJSON(doc string) {

file := path.Join("file:///", GetPath(), "/", doc)
box := packr.NewBox("./")
s := box.String("schema.json")
schemaLoader := gojsonschema.NewStringLoader(s)
documentLoader := gojsonschema.NewReferenceLoader(file)
result, err := gojsonschema.Validate(schemaLoader, documentLoader)
if err != nil {
panic(err.Error())
}

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)
}
}

}

// GetPath is used to get current path
func GetPath() string {
dir, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
return dir
}
20 changes: 20 additions & 0 deletions vendor/github.com/gobuffalo/packr/.codeclimate.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions vendor/github.com/gobuffalo/packr/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions vendor/github.com/gobuffalo/packr/.goreleaser.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions vendor/github.com/gobuffalo/packr/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions vendor/github.com/gobuffalo/packr/LICENSE.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

143 changes: 143 additions & 0 deletions vendor/github.com/gobuffalo/packr/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 65fdb0a

Please sign in to comment.