O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Open the console and create the folder chapter07/recipe07.
  2. Navigate to the directory.
  3. 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 header          resSlice := header["Auth-X"]          fmt.Println(resSlice)          // get the first value          resFirst := header.Get("Auth-X")          fmt.Println(resFirst)          // replace all existing values with          // this one          header.Set("Auth-X", "newvalue")          fmt.Println(header)          // Remove header          header.Del("Auth-X")          fmt.Println(header)        }
  1. Execute the code by running go run headers.go in the main Terminal. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required