httpreq

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package httpreq issues the service's outgoing HTTP requests with the trace context and the baggage of the caller attached.

It exists because the two Rancher drivers repeated the same four steps -- build, send, read, check the status -- around a request library that could not carry a context. Propagation has to happen on each of those calls, and a dozen copies of the same injection is a dozen chances to forget it.

Deliberately thin: it returns the status code and the raw body rather than decoding or classifying anything. The callers differ in what a status means to them -- a 404 while deleting is success, a 404 while looking a workload up is not -- so that judgement stays with them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicAuth

type BasicAuth struct {
	User     string
	Password string
}

BasicAuth is the credential pair the Rancher API is addressed with.

type Request

type Request struct {
	Method string
	URL    string
	// Body is JSON-encoded when it is not nil. A string or a []byte is sent as it
	// stands, for the callers that marshalled it themselves.
	Body      any
	Headers   map[string]string
	BasicAuth *BasicAuth
}

type Response

type Response struct {
	StatusCode int
	Body       []byte
}

func Do

func Do(ctx context.Context, request Request) (Response, error)

Do sends the request and reads the whole response.

Unlike the request library this replaced, a transport failure is returned as an error before the status is looked at. The old call sites read resp.StatusCode first and only then checked the error, which dereferences nil whenever the peer is unreachable.

func (Response) Decode

func (r Response) Decode(target any) error

Decode unmarshals the body into target.

func (Response) Text

func (r Response) Text() string

Text returns the body for an error message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL