How do I convert from a slice of interface{} to a slice of my struct type in Go? [duplicate]
- 阅读更多 关于 How do I convert from a slice of interface{} to a slice of my struct type in Go? [duplicate]
问题 This question already has answers here : Type converting slices of interfaces (6 answers) Closed 1 year ago . func GetFromDB(tableName string, m *bson.M) interface{} { var ( __session *mgo.Session = getSession() ) //if the query arg is nil. give it the null query if m == nil { m = &bson.M{} } __result := []interface{}{} __cs_Group := __session.DB(T_dbName).C(tableName) __cs_Group.Find(m).All(&__result) return __result } call GetFromDB(T_cs_GroupName, &bson.M{"Name": "Alex"}).([]CS_Group)