cache Schema unmarshalling, cache schema download failures (WIP)

This commit is contained in:
Yann Hamon 2020-05-30 21:40:54 +02:00
parent 87f1a0531e
commit 30a6fe69b1
4 changed files with 22 additions and 25 deletions

View file

@ -26,15 +26,13 @@ func (f ValidFormat) IsFormat(input interface{}) bool {
// gojsonschema.FormatCheckers.Add("int-or-string", ValidFormat{})
// }
func Validate(rawResource []byte, rawSchema []byte) error {
schemaLoader := gojsonschema.NewBytesLoader(rawSchema)
schema, err := gojsonschema.NewSchema(schemaLoader)
if err != nil {
return err
func Validate(rawResource []byte, schema *gojsonschema.Schema) error {
if schema == nil {
return nil
}
var resource map[string]interface{}
if err = yaml.Unmarshal(rawResource, &resource); err != nil {
if err := yaml.Unmarshal(rawResource, &resource); err != nil {
return fmt.Errorf("error unmarshalling resource: %s", err)
}
resourceLoader := gojsonschema.NewGoLoader(resource)