Skip to content

Instantly share code, notes, and snippets.

@albertoleal
Created December 11, 2014 15:20
Show Gist options
  • Save albertoleal/2ccae3e0acc704f87b71 to your computer and use it in GitHub Desktop.
Save albertoleal/2ccae3e0acc704f87b71 to your computer and use it in GitHub Desktop.
func (a *Auth) Login(email, password string) string {
url, err := GetURL("/api/login")
if err != nil {
return err.Error()
}
b := bytes.NewBufferString(`{"email":"` + email + `", "password":"` + password + `"}`)
req, err := http.NewRequest("POST", url, b)
if err != nil {
return err.Error()
}
client := NewClient(&http.Client{})
response, err := client.Do(req)
if err != nil {
httpEr := err.(*httpErr.HTTPError)
return httpEr.Message
}
var token = map[string]interface{}{}
parseBody(response.Body, &token)
writeToken(token["token_type"].(string) + " " + token["token"].(string))
return "Welcome! You've signed in successfully."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment