Skip to content

Instantly share code, notes, and snippets.

@simt2
Created February 21, 2017 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save simt2/08f6905f999d1291b0e996c00ee73a92 to your computer and use it in GitHub Desktop.
Save simt2/08f6905f999d1291b0e996c00ee73a92 to your computer and use it in GitHub Desktop.
mesh-go-example SessionCookie.go
// MeshLogin logs into the mesh backend and sets the session id
func MeshLogin(username string, password string) {
body := map[string]string{
"username": USERNAME,
"password": PASSWORD,
}
payload, _ := json.Marshal(body)
r, _ := http.Post(BASEURL+"auth/login", "application/json", bytes.NewBuffer(payload))
for _, cookie := range r.Cookies() {
if cookie.Name == "mesh.session" {
MeshSession = cookie.Value
}
}
}
// MeshGetRequest issues a logged in request to the mesh backend
func MeshGetRequest(path string) *http.Response {
url := BASEURL + path
req, _ := http.NewRequest(http.MethodGet, url, nil)
req.AddCookie(&http.Cookie{
Name: "mesh.session",
Value: MeshSession,
})
client := http.Client{}
resp, _ := client.Do(req)
return resp
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment