preparing for v0.5

This commit is contained in:
default
2024-08-01 10:06:42 +08:00
parent 24778d1093
commit 93359110a2
115 changed files with 5153 additions and 4395 deletions

26
src/utils/schema.go Normal file
View File

@@ -0,0 +1,26 @@
package utils
import (
"github.com/santhosh-tekuri/jsonschema"
"github.com/yusing/go-proxy/common"
)
var schemaCompiler = func() *jsonschema.Compiler {
c := jsonschema.NewCompiler()
c.Draft = jsonschema.Draft7
return c
}()
var schemaStorage = make(map[string] *jsonschema.Schema)
func GetSchema(path string) *jsonschema.Schema {
if common.NoSchemaValidation {
panic("bug: GetSchema called when schema validation disabled")
}
if schema, ok := schemaStorage[path]; ok {
return schema
}
schema := schemaCompiler.MustCompile(path)
schemaStorage[path] = schema
return schema
}