|
|
|
|
|
by vorg
2679 days ago
|
|
You could use a struct with private fields, e.g. 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)
...
}
|
|