golang-web参数校验
2021-05-29 21:02
标签:ejs gen infer not ola document range 相关 package 在线转换: Python转换: https://github.com/gonvaled/jskemator NodeJS转换: https://github.com/Nijikokun/generate-schema 红宝石: https://github.com/maxlinc/json-schema-generator NodeJS: 参考:https://www.ctolib.com/generate-schema.html https://www.lsdcloud.com/go/middleware/json-schema.html#_1-什么是json golang-web参数校验 标签:ejs gen infer not ola document range 相关 package 原文地址:https://www.cnblogs.com/tomtellyou/p/14701515.htmlgolang-web参数校验
json schema
package main
import (
"fmt"
"github.com/xeipuuv/gojsonschema"
)
func main() {
schemaLoader := gojsonschema.NewReferenceLoader("file:///home/me/schema.json")
documentLoader := gojsonschema.NewReferenceLoader("file:///home/me/document.json")
result, err := gojsonschema.Validate(schemaLoader, documentLoader)
if err != nil {
panic(err.Error())
}
if result.Valid() {
fmt.Printf("The document is valid\n")
} else {
fmt.Printf("The document is not valid. see errors :\n")
for _, desc := range result.Errors() {
fmt.Printf("- %s\n", desc)
}
}
}
json转json-schema
https://www.jsonschema.net/home
https://easy-json-schema.github.io/
https://www.liquid-technologies.com/online-json-to-schema-converter
https://github.com/perenecabuto/json_schema_generator
https://github.com/rnd0101/json_schema_inferencer
https://pypi.python.org/pypi/genson/
https://pypi.python.org/pypi/skinfer
https://github.com/easy-json-schema/easy-json-schemanpm install generate-schema --save
var GenerateSchema = require(‘generate-schema‘)
// Capture Schema Output
var schema = GenerateSchema.json(‘Product‘, [
{
"id": 2,
"name": "An ice sculpture",
"price": 12.50,
"tags": ["cold", "ice"],
"dimensions": {
"length": 7.0,
"width": 12.0,
"height": 9.5
},
"warehouseLocation": {
"latitude": -78.75,
"longitude": 20.4
}
},
{
"id": 3,
"name": "A blue mouse",
"price": 25.50,
"dimensions": {
"length": 3.1,
"width": 1.0,
"height": 1.0
},
"warehouseLocation": {
"latitude": 54.4,
"longitude": -32.7
}
}
])
json-chema转golang struct: https://zhuanlan.zhihu.com/p/350162109相关链接
https://www.cnblogs.com/makelu/p/11828274.html
http://json-schema.org/implementations.html#validator-go
https://github.com/xeipuuv/gojsonschema
https://github.com/santhosh-tekuri/jsonschema