upstream

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package upstream records one entry per attempted upstream mirror so a fetch that failed across every mirror can be logged with each mirror's own error. Retry loops used to keep a single lastErr variable, which meant a mirror's TLS or DNS failure was silently replaced by the next mirror's plain 404.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SanitizeURL

func SanitizeURL(raw string) string

SanitizeURL removes any userinfo component. An unparseable URL is returned unchanged: it came from configuration, and hiding it entirely would be worse than logging it verbatim.

Types

type Attempt

type Attempt struct {
	URL      string
	Status   int
	Err      error
	Duration time.Duration
}

Attempt is one mirror's outcome. Status is the upstream HTTP status, or 0 when the request never produced a response at all (TLS verification, DNS, connection refused, timeout, an open circuit breaker). That distinction is the reason this type exists: a 0 and a 404 mean very different things to an operator, and collapsing them hides misconfigured mirrors.

type Attempts

type Attempts []Attempt

Attempts is the ordered list of mirror outcomes for one logical fetch. It implements error, so a retry loop can return it directly, and zerolog.LogArrayMarshaler, so a log site can render every attempt as one structured array field.

func AttemptsFrom

func AttemptsFrom(err error) (Attempts, bool)

AttemptsFrom recovers the attempts from err, including when err wraps them. Log sites use it to attach the structured array to an error they did not produce themselves.

func (*Attempts) Add

func (a *Attempts) Add(rawURL string, status int, err error, d time.Duration)

Add appends one outcome. Credentials embedded in rawURL are stripped from the resulting URL field only. err's own text is not sanitised: it is the caller's responsibility. In practice net/http masks a *url.Error's password but leaves the username, and http.NewRequestWithContext on a malformed URL returns the raw URL unmasked.

func (Attempts) AllNotFound

func (a Attempts) AllNotFound() bool

AllNotFound reports whether every mirror answered 404 or 410 — the condition under which the proxy returns 404 rather than 502. An empty list is false: nothing was tried, so nothing proved the artifact absent.

func (Attempts) Error

func (a Attempts) Error() string

Error renders every attempt, so the flat message of a wrapped error still carries all mirrors even where the structured array is unavailable.

func (Attempts) MarshalZerologArray

func (a Attempts) MarshalZerologArray(arr *zerolog.Array)

MarshalZerologArray renders the attempts as an array of objects.

func (Attempts) Unwrap

func (a Attempts) Unwrap() []error

Unwrap exposes the individual errors to errors.Is / errors.As.

Jump to

Keyboard shortcuts

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