The previous recipe describes how you can create a HTTP request in general. This recipe will go into detail on how to read and write request headers.
Reading and writing HTTP headers
How to do it...
- Open the console and create the folder chapter07/recipe07.
- Navigate to the directory.
- Create the headers.go file with the following content:
package main
import (
"fmt"
"net/http"
)
func main() {
header := http.Header{}
// Using the header as slice
header.Set("Auth-X", "abcdef1234")
header.Add("Auth-X", "defghijkl")
fmt.Println(header)
// retrieving slice of values in...