Skip to content
This repository has been archived by the owner on Jul 18, 2022. It is now read-only.

Commit

Permalink
Fix schema location and tolerate loading errors
Browse files Browse the repository at this point in the history
  • Loading branch information
fbiville committed Jan 24, 2019
1 parent 32a7439 commit afd210e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ func readConfiguration(configFile *string, reader fs.FileReader) Configuration {
}

func validateConfiguration(reader fs.FileReader, configFile *string) {
schema := loadSchema()
if schema == nil {
return
}
jsonSchemaValidator := JsonSchemaValidator{
Schema: loadSchema(),
Schema: schema,
FileReader: reader,
}
validationError := jsonSchemaValidator.Validate("file://" + *configFile)
Expand All @@ -73,9 +77,10 @@ func validateConfiguration(reader fs.FileReader, configFile *string) {
}

func loadSchema() *jsonsch.Schema {
schema, err := jsonsch.NewSchema(jsonsch.NewReferenceLoader("file://docs/schema.json"))
schema, err := jsonsch.NewSchema(jsonsch.NewReferenceLoader("https://fbiville.github.io/headache/v1.0.0-M01/schema.json"))
if err != nil {
log.Fatalf("headache configuration error, cannot load JSON schema\n\t%v\n", err)
log.Printf("headache configuration warning: cannot load schema, skipping configuration validation. See reason below:\n\t%v\n", err)
return nil
}
return schema
}

0 comments on commit afd210e

Please sign in to comment.