在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:a-h/generate开源软件地址:https://github.com/a-h/generate开源编程语言:Go 98.5%开源软件介绍:generateGenerates Go (golang) Structs and Validation code from JSON schema. Requirements
UsageInstall $ go get -u github.com/a-h/generate/... or Build $ make Run $ schema-generate exampleschema.json ExampleThis schema {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Example",
"id": "http://example.com/exampleschema.json",
"type": "object",
"description": "An example JSON Schema",
"properties": {
"name": {
"type": "string"
},
"address": {
"$ref": "#/definitions/address"
},
"status": {
"$ref": "#/definitions/status"
}
},
"definitions": {
"address": {
"id": "address",
"type": "object",
"description": "Address",
"properties": {
"street": {
"type": "string",
"description": "Address 1",
"maxLength": 40
},
"houseNumber": {
"type": "integer",
"description": "House Number"
}
}
},
"status": {
"type": "object",
"properties": {
"favouritecat": {
"enum": [
"A",
"B",
"C"
],
"type": "string",
"description": "The favourite cat.",
"maxLength": 1
}
}
}
}
} generates package main
type Address struct {
HouseNumber int `json:"houseNumber,omitempty"`
Street string `json:"street,omitempty"`
}
type Example struct {
Address *Address `json:"address,omitempty"`
Name string `json:"name,omitempty"`
Status *Status `json:"status,omitempty"`
}
type Status struct {
Favouritecat string `json:"favouritecat,omitempty"`
} See the test/ directory for more examples. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论