Skip to content
Node: axios, fetchgithub.com/sahilkhaire/gox/client

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) *RequestOpts

Compare: Node.js · Standard Go · gox

js
// Typical axios, fetch pattern in Node.js
go
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)

Back to client package overview

MIT Licensed · Built for Node.js developers moving to Go