Standard library / net/http
http.Header.Clone()
Copy headers and value slices so changes do not alter the original. Expected stdout: 'a b\n'.
Formal Syntax & Structure
go syntaxgo
func (h Header) Clone() HeaderReturn Value
Header
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "net/http")
func main() { h := http.Header{} h.Set("X-Demo", "a") c := h.Clone() c.Set("X-Demo", "b") fmt.Println(h.Get("X-Demo"), c.Get("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) }}