美文网首页
12:golang struct 切片数组去重

12:golang struct 切片数组去重

作者: 陈玉涛 | 来源:发表于2020-03-17 17:14 被阅读0次
    type Fts_message_table_content_nomal struct {
        Docid          int64  `xorm:"docid"`
        C0CreateTime   int64  `xorm:"c0CreateTime"`
        C1MesLocalID   int64  `xorm:"c1MesLocalID"`
        C2Message      string `xorm:"c2Message"`
        C3reservedInt  string `xorm:"c3reservedInt"`
        C4reservedText string `xorm:"c4reservedText"`
        C5usernameid   int64  `xorm:"c5usernameid"`
        C6CONSTRAINT   string `xorm:"c6CONSTRAINT"`
    }
    type Message_contents_normal []Fts_message_table_content_nomal
    func removeDuplicate(personList Message_contents_normal) Message_contents_normal {
        resultMap := map[string]bool{}
        for _, v := range personList {
            data, _ := json.Marshal(v)
            resultMap[string(data)] = true
        }
        result := Message_contents_normal{}
        for k := range resultMap {
            var t Fts_message_table_content_nomal
            json.Unmarshal([]byte(k), &t)
            result = append(result, t)
        }
        return result
    }
    
    

    相关文章

      网友评论

          本文标题:12:golang struct 切片数组去重

          本文链接:https://www.haomeiwen.com/subject/dwztyhtx.html