package main import ( "encoding/json" "fmt" "io" ) // UserList stores a collection of users. type UserList []User // Find tries to return username from UserList func (ul UserList) Find(username string) *User { for i, u := range ul { if u.Username == username { return &ul[i] } } return nil } // NewUserList creates a UserList from JSON func NewUserList(rdr io.Reader) (UserList, error) { var userList []User err := json.NewDecoder(rdr).Decode(&userList) if err != nil { err = fmt.Errorf("problem parsing userlist, %v", err) } return userList, err }