Hi,
I am trying to save a cookie (which work) and get the values back.
The code used are from (there are several similar links out there basically the same code):
https://git.schlagma.de/kulinari/kulinari-server/src/commit/096111466d81e4bfc91ccf1aab5723a3177308cf/cookie.go?lang=sv-EN
func getuser(r *http.Request) string {
var usr string
if cookie, err := r.Cookie("session"); err == nil {
cookieValue := make(map[string]string)
if err = cookieHandler.Decode("session", cookie.Value, &cookieValue); err == nil {
usr = cookieValue["name"]
}
fmt.Println("---cookie.Value---")
fmt.Println(cookie.Value)
fmt.Println("---cookie.Value---")
fmt.Println("---cookieValue---")
fmt.Println(cookieValue)
fmt.Println("---cookieValue---")
fmt.Println("---usr---")
fmt.Println(usr)
fmt.Println("---usr---")
}
return usr
}
The result of this code is that I can fetch the encrypted value, but not the decoded.
—cookie.Value— (seems to be OK)
TU5MjE0NTA2NXxkTnl3Mll6ZXZMeGhBeWVVYXRmMklFUHU4VFRXZWV3dGNyMktXMUt0ckE2SHAwM1M3MlJleUNDV2FGdWpFVW5SRUdmNjJ0N1MtTEV0cndPcW5BPT18AuIFYfSD96wKkbwWk7lTQLZgh8d1CHtsk1oHCNSI8vU=
—cookie.Value—
—cookieValue—(The map is empty)>
map
—cookieValue—
—usr— (no user name)
—usr—
What am I doing wrong? Or thinking wrong?