neo4j 返回数据转 golang 数据类型

shaotteng · · 920 次点击 · 开始浏览    置顶
这是一个创建于 的主题,其中的信息可能已经有所发展或是发生改变。

```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"}}, ] } ``` 谢谢

有疑问加站长微信联系(非本文作者)

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

920 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传