Created
December 27, 2017 15:11
-
-
Save caalberts/1b7b2b14a29695e0f663c6ece219e62a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (r *AccountRepository) FetchAccount(id string) (*Account, error) { | |
data, err := r.client.HGetAll(id) | |
if err != nil { | |
return nil, err | |
} | |
return toAccount(data) | |
} | |
type Account struct { | |
Id string | |
Name string | |
Balance int | |
} | |
func toAccount(data map[string]string) (*Account, error) { | |
if _, ok := data["Id"]; !ok { | |
return nil, errors.New("Missing account ID") | |
} | |
balance, err := strconv.Atoi(data["Balance"]) | |
if err != nil { | |
return nil, err | |
} | |
return &Account{ | |
Id: data["Id"], | |
Name: data["Name"], | |
Balance: balance, | |
}, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment