Skip to content

Commit

Permalink
draft: use embed.FS for metaschemas
Browse files Browse the repository at this point in the history
  • Loading branch information
santhosh-tekuri committed Feb 8, 2024
1 parent cee473f commit 4fd61a4
Show file tree
Hide file tree
Showing 21 changed files with 1,153 additions and 1,160 deletions.
18 changes: 14 additions & 4 deletions compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,21 @@ func (c *Compiler) Compile(url string) (*Schema, error) {

func (c *Compiler) findResource(url string) (*resource, error) {
if _, ok := c.resources[url]; !ok {
// load resource
var rdr io.Reader
if sch, ok := vocabSchemas[url]; ok {
rdr = strings.NewReader(sch)
} else {

u, meta := strings.CutPrefix(url, "http://json-schema.org/")
if !meta {
u, meta = strings.CutPrefix(url, "https://json-schema.org/")
}
if meta {
f, err := metaFiles.Open("metaschemas/" + u)
if err == nil {
rdr = f
}
}

// load resource
if rdr == nil {
loadURL := LoadURL
if c.LoadURL != nil {
loadURL = c.LoadURL
Expand Down
Loading

0 comments on commit 4fd61a4

Please sign in to comment.