Skip to content

Commit

Permalink
another shitty way of loading the schema reference
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickwieth committed Aug 25, 2019
1 parent 12d4130 commit c5f2196
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
module github.com/DecentralCardGame/cardobject

go 1.12

require (
github.com/xeipuuv/gojsonpointer v0.0.0-20190809123943-df4f5c81cb3b // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.1.0
)
15 changes: 11 additions & 4 deletions serializeCard.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cardobject

import "fmt"
import "os"
//import "io/ioutil"
import "github.com/xeipuuv/gojsonschema"
import "encoding/json"
Expand All @@ -25,10 +26,16 @@ func ProcessCard (cardJson string) string {
}

func validateCard(s string) bool {
//file, err := ioutil.ReadFile("schema/cardschema.json")
//fmt.Println(file)

schemaLoader := gojsonschema.NewReferenceLoader("file://schema/cardSchema.json")
/*
// read the file with the schema
file, err := ioutil.ReadFile("./schema/cardSchema.json")
if err != nil {
fmt.Println("\x1b[31;1mreading schema/cardschema.json failed\x1b[0m")
}
fmt.Println(string(file))
*/
//schemaLoader := gojsonschema.NewStringLoader(string(file))
schemaLoader := gojsonschema.NewReferenceLoader("file://"+os.Getenv("$GOPATH")+"schema/cardSchema.json")
documentLoader := gojsonschema.NewStringLoader(s)

result, err := gojsonschema.Validate(schemaLoader, documentLoader)
Expand Down

0 comments on commit c5f2196

Please sign in to comment.