```bash
dbtype.Path{Nodes:[]dbtype.Node{dbtype.Node{Id:19, ElementId:"19", Labels:[]string{"MODEL"}, Props:map[string]interface {}{"_version":1, "model_name":"应用", "name":"APP", "object_id":"APP"}}, dbtype.Node{Id:28, ElementId:"28", Labels:[]string{"ATTR"}, Props:map[string]interface {}{"attr_id":"nickname", "description":"简称", "name":"nickname"}}}, Relationships:[]dbtype.Relationship{dbtype.Relationship{Id:25, ElementId:"25", StartId:19, StartElementId:"19", EndId:28, EndElementId:"28", Type:"ATTR", Props:map[string]interface {}{"key":"internal"}}}}
dbtype.Path{Nodes:[]dbtype.Node{dbtype.Node{Id:19, ElementId:"19", Labels:[]string{"MODEL"}, Props:map[string]interface {}{"_version":1, "model_name":"应用", "name":"APP", "object_id":"APP"}}, dbtype.Node{Id:31, ElementId:"31", Labels:[]string{"ATTR"}, Props:map[string]interface {}{"attr_id":"version", "description":"版本", "name":"version"}}}, Relationships:[]dbtype.Relationship{dbtype.Relationship{Id:26, ElementId:"26", StartId:19, StartElementId:"19", EndId:31, EndElementId:"31", Type:"ATTR", Props:map[string]interface {}{"key":"internal"}}}}
dbtype.Path{Nodes:[]dbtype.Node{dbtype.Node{Id:19, ElementId:"19", Labels:[]string{"MODEL"}, Props:map[string]interface {}{"_version":1, "model_name":"应用", "name":"APP", "object_id":"APP"}}, dbtype.Node{Id:31, ElementId:"31", Labels:[]string{"ATTR"}, Props:map[string]interface {}{"attr_id":"version", "description":"版本", "name":"version"}}, dbtype.Node{Id:32, ElementId:"32", Labels:[]string{"VALUE"}, Props:map[string]interface {}{"valueType":"str"}}}, Relationships:[]dbtype.Relationship{dbtype.Relationship{Id:26, ElementId:"26", StartId:19, StartElementId:"19", EndId:31, EndElementId:"31", Type:"ATTR", Props:map[string]interface {}{"key":"internal"}}, dbtype.Relationship{Id:27, ElementId:"27", StartId:31, StartElementId:"31", EndId:32, EndElementId:"32", Type:"VALUE", Props:map[string]interface {}{"key":"value"}}}}
```
上面这个是 neo4j 返回的 path 类型示例,有没有什么好的方法,转为自己定义的结构体:
结构体定义如下:
```golang
type Model struct {
ObjectID string `json:"object_id"`
Name string `json:"name"`
Description string `json:"description"`
Version int64 `json:"_version"`
Internal []*AttrJSON `json:"internal"`
External []*Model `json:"external"`
}
type AttrJSON struct {
AttrID string `json:"attrId"`
Name string `json:"name"`
Value ValueStatement `json:"value"`
}
type ValueStatement struct {
ValueType string `json:"valueType"`
}
```
最后的结果类似:
```json
{
"_version":1, "model_name":"应用", "name":"APP", "object_id":"APP"
"internal":[
{"attr_id":"nickname", "description":"简称", "name":"nickname"},
{"attr_id":"version", "description":"版本", "name":"version",value:{"valueType":"str"}},
]
}
```
谢谢
有疑问加站长微信联系(非本文作者)