by twentythree · 7y ago · 0 comments
What's the best way to handle a situation where you use two different types for the same data? e.g.
var usersMap map[string]*User
var usersList []*User var usersByUsername map[string]*User
var usersToEmail []*User type Users struct{
dict map[string]*User
list []*User
}
and attach methods to both access the data and coordinatedly update both forms, e.g. func (us *Users) byID(id string) *User { ... }
func (us *Users) sortedByID() []*User { ... }
func (us *Users) addUser(id string, nu *User) {
dict[id] = nu
list = append(list, nu)
...
}