Golang gets a collection of fields in the map of an array (beego framework)

the data obtained from MySQL is as follows

[map[Uid:3 Avatar:12 Username:jack Level: Content:1212 Created_at:1540447583 Id:1] map[Username:jack Level: Content:1212 Created_at:1540447612 Id:2 Uid:3 Avatar:12]]

how to efficiently get the Uid collection in this array, and then use the Uid collection to look up the data in the user table and splice it together.

in addition, the demo I wrote myself is as follows


func (c *UserController) ChatMsgList() {
    o := orm.NewOrm()
    qs := o.QueryTable("chat_msg")

    var list []orm.Params
    qs.OrderBy("Id").Limit(2).Values(&list)
    beego.Info(list)
    var uids []int
    //listUid

    for key, value := range list {
        beego.Info(key)
        uids = append(uids, value["Uid"])
    }

    beego.Info(uids)

    //c.Data["list"] = list
    //
    //c.TplName = "user/chatMsgList.html"
    c.Data["json"] = list
    c.ServeJSON()
}
Oct.09,2021

can only loop.. After all, you use map to receive data
gorm.


is a little disappointed that so many golang programmers don't know how to write it.


you can use https://github.com/chenhg5/co. to provide convenient operations for various map/ arrays

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3de5a-2c3c1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3de5a-2c3c1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?