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 it works...

The headers in the http package are, in fact, represented as map[string][]string, and this way, the Header type must be handled. The preceding code shows how to set and read the header values. The important thing about the header is that the value of the header key is the string slice. So, each key in a header can contain multiple values.

The Set method of the Header type sets the one-item slice under the given key. On the other hand, the Add method appends the values to the slice.

Using the Get method will retrieve the first value from the slice under the given key. If the whole slice is needed, the Header needs to be handled as a map. The whole header key can be removed by using the Del method.

Both the server and client ...

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