title: load multiple gojsonschemas for later use
body: <p>I am trying to manage json validation for my rest API. I have decided to implement using <code>github.com/xeipuuv/gojsonschema</code> package.</p>
  
  <pre><code>func (a Auth) Login(w http.ResponseWriter, r *http.Request) {
  
      bodyBytes, err := ioutil.ReadAll(r.Body)
      if err != nil {
          w.WriteHeader(http.StatusBadRequest)
          return
      }
  
      cwd, _ := os.Getwd()
      src := "file://" + cwd + "/schemas/auth.json"
  
      schemaLoader := gojsonschema.NewReferenceLoader(src)
      ...
  </code></pre>
  
  <p>Above works fine, but I am not happy, because for every API request, The schema needs to be loaded.</p>
  
  <p>So in my app setup, I want to load ALL schemas into a map of schemas for later use.</p>
  
  <pre><code>package schemas
  
  import (
      "os"
      "path/filepath"
      "strings"
  
      "github.com/xeipuuv/gojsonschema"
  )
  
  const ext = ".json"
  
  func LoadSchemas() error {
      pathS, err := os.Getwd()
      if err != nil {
          return err
      }
  
      var files = make(map[string]*gojsonschema.jsonReferenceLoader) // This is where I am stuck...
      filepath.Walk(pathS+"/schemas", func(path string, f os.FileInfo, _ error) error {
          if !f.IsDir() {
              if filepath.Ext(path) == ext {
                  key := strings.TrimRight(f.Name(), ext)
                  files[key] = gojsonschema.NewReferenceLoader("file://" + path)
              }
          }
          return nil
      })
  
      return nil
  }
  </code></pre>
  
  <p><code>gojsonschema.NewReferenceLoader("file://" + path)</code> returns <code>*jsonReferenceLoader</code> - jsonReferenceLoader is not exported outside the package.</p>
  
  <pre><code>// NewReferenceLoader returns a JSON reference loader using the given source and the local OS file system.
  func NewReferenceLoader(source string) *jsonReferenceLoader {
      return &amp;jsonReferenceLoader{
          fs:     osFS,
          source: source,
      }
  }
  </code></pre>
  
  <p>Any hints / tips on how to solve the above problem?</p>