【发布时间】:2015-01-20 07:32:56
【问题描述】:
我有兴趣阅读模式(json 格式的文本文件)并将其解组为模式(为此我在 .GO 文件中定义了一些 JSON 结构)并且对于模式中的每种类型的结构,我想生成一个相应的 .go 文件,其中包含使用模板包 (http://golang.org/pkg/text/template/) 执行 CRUD 操作以生成这些文件的代码。
架构文件中的结构示例 - {
type struct XYZ {
Type string `json:"type,omitempty"`
ResourceType string `json:"resourceType,omitempty"`
Links map[string]string `json:"links,omitempty"`
}
The text file has a JSON structured data which is something of this form -
{
"type": "collection",
"resourceType": "schema",
"links": {
"self": "…/v1/schemas",
},
"createTypes": { },
"actions": { },
"data": [ 86 items
{
"id": "schema",
"type": "schema",
"links": {
"self": "/schemas/schema",
"collection": "…/schemas",
},
...
}
}
有人可以帮我,我怎么可能使用 GO 模板包为不同的结构生成这些 CRUD 操作的代码。
【问题讨论】:
标签: json go go-templates