This is a creation in Article, where the information may have evolved or changed.
In today's project to deposit a map into a cookie, elephant brother studied JSON and Base64 and wrote a small example
A. Deposit a map into a cookie
Mapyour to deposit the cookie: = map[string]string{}your["IsUser"] = isuseryour["username"] = usernameyour["password"] = d. STRTOMD5 (password)//convert map to JSON conversion is []byte, after the string (Your_byte) is the JSON your_byte, _: = json. Marshal (your)//JSON base64 a bit b64: = base64. Newencoding ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/") your_string: = b64. Encodetostring (Your_byte) fmt. PRINTLN (your_string)//The second base64 way your_string = base64. Stdencoding.encodetostring (Your_byte) fmt. PRINTLN (your_string)//Storage cookiethis. Ctx.setcookie ("Your", your_string)
Second, read the map in the cookie
Read the variable in the cookie your_string: = this. Ctx.Input.Cookie ("your")//Parse into jsonb64: = base64. Newencoding ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/") Your_to_byte, _: = B64. Decodestring (your_string) Your: = String (your_to_byte) fmt.println (Your)