I am reading official documentation about Go language and found:
Cookie
returns the named cookie provided in the request
When I try req.Cookie("My-Cookie")
I receive named cookie not present
While when I fmt.Println(req.Cookies())
I receive following string:
[My-Cookie=a783e7e4-c331-4802-6544-7374f5128882 Path=/svc Expires="Tue, 07 Feb 2068 16:05:53 GMT" Path=/svc HttpOnly=]
What is the named cookie then?
Here is a golang playground. It shows that what the OP posted works, so the bug is somewhere else. It also answers the question by showing what the named cookie is.
package main
import (
"fmt"
"net/http"
)
func main() {
r := &http.Request{
Header: http.Header{
"Cookie": []string{
"My-Cookie=a783e7e4-c331-4802-6544-7374f5128882 Path=/svc Expires=Tue, 07 Feb 2068 16:05:53 GMT Path=/svc HttpOnly=",
},
},
}
fmt.Println(r.Cookies())
c, err := r.Cookie("My-Cookie")
if err != nil {
fmt.Println("Error:", err)
return
}
// only cookie name and value are parsed
fmt.Println("Name", c.Name)
fmt.Println("Value", c.Value)
}