Standard library / net/http

http.Header.Set()

Replace all values of the canonical header key. Expected stdout: '[b]\n'.

Formal Syntax & Structure

go syntaxgo
func (h Header) Set(key, value string)

Parameters & Attributes

NameTypeDescription
keystringHeader or query parameter name.
valuestringValue to store.

Working Example

Example Snippetgo
package main
import (  "fmt"  "net/http")
func main() {  h := http.Header{}  h.Set("X-Demo", "a")  h.Set("x-demo", "b")  fmt.Println(h.Values("X-Demo"))}
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