How it works...
The net/http package also provides the functions and mechanisms to operate on cookies. The sample code presents how to set/get and remove the cookies. The SetCookie function accepts the Cookie struct pointer that represents the cookies, and naturally the ResponseWriter. The Name, Value, Domain, and expiration are set directly in the Cookie struct. Behind the scenes, the SetCookie function writes the header to set the cookies.
The cookie values could be retrieved from the Request struct. The method Cookie with the name parameter returns the pointer to the Cookie, if the cookie exists in the request.
To list all cookies within the request, the method Cookies could be called. This method returns the slice of the Cookie structs ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access