diff --git a/go.mod b/go.mod index f23ab60..abee5ab 100644 --- a/go.mod +++ b/go.mod @@ -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 +) diff --git a/serializeCard.go b/serializeCard.go index a4fba48..07b3697 100644 --- a/serializeCard.go +++ b/serializeCard.go @@ -1,6 +1,7 @@ package cardobject import "fmt" +import "os" //import "io/ioutil" import "github.com/xeipuuv/gojsonschema" import "encoding/json" @@ -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)