Skip to content

Instantly share code, notes, and snippets.

@c4milo
Created February 26, 2015 01:14
Show Gist options
  • Save c4milo/5bdd3788db601b19fb89 to your computer and use it in GitHub Desktop.
Save c4milo/5bdd3788db601b19fb89 to your computer and use it in GitHub Desktop.
// GetByID returns an Account instance given its id which is either:
// username or email.
func (r *RepoPostgres) GetByID(id string) (*Account, error) {
a := new(account)
err := r.db.Get(a, "SELECT * FROM accounts WHERE username = $1 OR email = $1", id)
if err != nil {
return nil, translateError(err)
}
a.Account.PictureURL, _ = url.Parse(a.PictureURL)
a.Account.Type = AccountType(a.Type)
a.Account.Status = StatusType(a.Status)
return &(a.Account), nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment