RequestOpts.WithHeaders
Overview
WithHeaders returns RequestOpts with headers.
Part of the client package — Node.js analog: axios, fetch.
Method on RequestOpts — call it on a value of that type after constructing or receiving one from a constructor.
Signature
go
func WithHeaders(h http.Header) *RequestOptsCompare: Node.js · Standard Go · gox
js
// Typical axios, fetch pattern in Node.jsgo
resp, err := http.NewRequestWithContext(ctx, method, url, body)
client.Do(req)go
import "github.com/sahilkhaire/gox/client"
opts := client.RequestOpts{}.WithHeaders(map[string]string{"Authorization": "Bearer token"})Example
go
import "github.com/sahilkhaire/gox/client"
opts := client.RequestOpts{}.WithHeaders(map[string]string{"Authorization": "Bearer token"})Tips
Pass context.Context as the first argument so cancellation and deadlines propagate correctly.
Standard library alternative
Use the standard library directly:
go
resp, err := http.NewRequestWithContext(ctx, method, url, body)
client.Do(req)