Skip to content

Instantly share code, notes, and snippets.

@tamasd
Last active December 11, 2015 21:38
Show Gist options
  • Save tamasd/4663377 to your computer and use it in GitHub Desktop.
Save tamasd/4663377 to your computer and use it in GitHub Desktop.
func login(username, password string) *http.Cookie {
resp := post("user/login", fmt.Sprintf("username=%s&password=%s", url.QueryEscape(username), url.QueryEscape(password)), nil)
if resp.StatusCode != http.StatusCodeOK {
log.Fatal(resp.Status)
}
jsondata := getBody(resp)
var lr LoginResponse
if err := json.Unmarshal(jsondata, &lr); err != nil {
log.Fatal(err)
}
return &http.Cookie{Name: lr.SessionName, Value: lr.SessionID}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment