Skip to content

Instantly share code, notes, and snippets.

@jpukg
Forked from simt2/SessionCookie.go
Created February 14, 2022 10:05
Show Gist options
  • Save jpukg/6f874799e6a1174a4000c6ff98d2b16d to your computer and use it in GitHub Desktop.
Save jpukg/6f874799e6a1174a4000c6ff98d2b16d 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