12:golang struct 切片数组去重
2020-03-17 本文已影响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
}