最近发布的主题
最近发布的文章
最近分享的资源
暂无
最近发布的项目
暂无
最近的评论
-
评论了博文 用golang 写了一个问答系统
-
评论了博文 用golang 写了一个问答系统我看了你那个网址,你的seo基本没优化。。。 你用nuxt 渲染,html代码太乱,很多行内式,script标签,这在seo中都是不建议出现的
-
评论了博文 用golang 写了一个问答系统
-
这是调用代码 感觉很不完善 ```go package manage import ( "ask/dd" "ask/model" "ask/ot" "github.com/gin-gonic/gin" ) func NodeList(c *gin.Context) { node_list := []model.Node{} dd.Find(dd.FindConstructor{}, &node_list) c.JSON(200, ot.Success(node_list, "")) } ```
-
#4楼 @czyt 就是封装mongodb 查询函数 第一个参数为 ``` type FindConstructor struct { Where bson.M } ``` 第二个参数 `interface` 这个用来接受查询数据的返回值 遇到的问题是 第二个内存地址换了导致 不会有数据返回 但是使用 json.Unmarshal 能达到要求 所有完整代码如下 ``` func Find(cstor FindConstructor, data interface{}) (findstatus FindStatusCode) { d2 := []interface{}{} table_name := getCollName(data) find, err := db.Coll(table_name).Find(db.TimeOut(), cstor.Where) if err != nil { findstatus = checkMongoErr(err) return } err = find.All(db.TimeOut(), &d2) if err != nil { findstatus = checkMongoErr(err) return } var errbson error var temporaryBytes []byte var json_list = [][]byte{} for _, v := range d2 { temporaryBytes, errbson = bson.MarshalExtJSON(v, true, true) if errbson != nil { continue } json_list = append(json_list, temporaryBytes) } j := bytes.Join(json_list, []byte(",")) j2 := "[" + string(j) + "]" err = json.Unmarshal([]byte(j2), &data) return } ```