Standard library / net/http

http.Cookie

Represents HTTP cookie fields. Path, Domain, Secure, HttpOnly and SameSite describe scope or browser restrictions; never store secrets in example output. Expected stdout: 'demo true\n'.

Formal Syntax & Structure

go syntaxgo
type Cookie struct {  Name   string  Value  string  Quoted bool
  Path       string  Domain     string  Expires    time.Time  RawExpires string
  MaxAge      int  Secure      bool  HttpOnly    bool  SameSite    SameSite  Partitioned bool  Raw         string  Unparsed    []string}

Working Example

Example Snippetgo
package main
import (  "fmt"  "net/http")
func main() {  c := http.Cookie{Name: "demo", Value: "yes", Path: "/", HttpOnly: true}  check(c.Valid())  fmt.Println(c.Name, c.HttpOnly)}
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