Here's an example of how to create an HTTP server in Go and parse cookies:
main.go456 chars25 linesIn this example, we create an HTTP server and set the handler function to handleRequest. In handleRequest, we use http.Request to parse cookies via the Cookies() method. We then iterate over the cookies and print each one's name and value using http.ResponseWriter. Finally, we print "Hello, World!".
Note that for testing cookie parsing, you can pass a cookie to the server using the -H flag in curl:
main.go51 chars2 lines
This will pass a cookie with the name "key" and the value "value" to the server.
gistlibby LogSnag