Standard library / net/http

http.ParseCookie()

Parse a Cookie request header into name/value pairs. Repeated names may occur. Expected stdout: '2 2\n'.

Formal Syntax & Structure

go syntaxgo
func ParseCookie(line string) ([]*Cookie, error)

Parameters & Attributes

NameTypeDescription
linestringRaw cookie header field value.

Return Value

([]*Cookie, error)

Operation result; check errors and validity indicators when returned.

Working Example

Example Snippetgo
package main
import (  "fmt"  "net/http")
func main() { c := must(http.ParseCookie("a=1; a=2")); fmt.Println(len(c), c[1].Value) }
func must[T any](v T, e error) T {  if e != nil {    panic(e)  }  return v}func check(e error) {  if e != nil {    panic(e)  }}
Go Reference