Documentation
¶
Index ¶
- Variables
- type Cache
- func (c *Cache) GetHostname() string
- func (c *Cache) GetNar(ctx context.Context, narURL nar.URL, mutators ...func(*http.Request)) (*http.Response, error)
- func (c *Cache) GetNarInfo(ctx context.Context, hash string) (*narinfo.NarInfo, error)
- func (c *Cache) GetPriority() uint64
- func (c *Cache) HasNar(ctx context.Context, narURL nar.URL, mutators ...func(*http.Request)) (bool, error)
- func (c *Cache) HasNarInfo(ctx context.Context, hash string) (bool, error)
- func (c *Cache) IsHealthy() bool
- func (c *Cache) NarInfoExistence(ctx context.Context, hash string) Existence
- func (c *Cache) ParsePriority(ctx context.Context) (uint64, error)
- func (c *Cache) PublicKeys() []signature.PublicKey
- func (c *Cache) SetHealthy(isHealthy bool)
- func (c *Cache) SetPriority(priority uint64)
- type Existence
- type NetrcCredentials
- type Options
Constants ¶
This section is empty.
Variables ¶
var ( // ErrURLRequired is returned if the given URL to New is not given. ErrURLRequired = errors.New("the URL is required") // ErrURLMustContainScheme is returned if the given URL to New did not contain a scheme. ErrURLMustContainScheme = errors.New("the URL must contain scheme") // ErrInvalidURL is returned if the given hostName to New is not valid. ErrInvalidURL = errors.New("the URL is not valid") // ErrNotFound is returned if the nar or narinfo were not found. ErrNotFound = errors.New("not found") // ErrInvalidNarInfo is returned if the given narinfo is invalid. ErrInvalidNarInfo = errors.New("invalid narinfo") // ErrUnexpectedHTTPStatusCode is returned if the response has an unexpected status code. ErrUnexpectedHTTPStatusCode = errors.New("unexpected HTTP status code") // ErrSignatureValidationFailed is returned if the signature validation of the narinfo has failed. ErrSignatureValidationFailed = errors.New("signature validation has failed") // ErrTransportCastError is returned if it was not possible to cast http.DefaultTransport to *http.Transport. ErrTransportCastError = errors.New("unable to cast http.DefaultTransport to *http.Transport") )
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache represents the upstream cache service.
func New ¶
New creates a new upstream cache with the given URL and options. Pass nil for opts to use default values.
func (*Cache) GetNar ¶
func (c *Cache) GetNar(ctx context.Context, narURL nar.URL, mutators ...func(*http.Request)) (*http.Response, error)
GetNar returns the NAR archive from the cache server. It always sends Accept-Encoding: zstd to request compressed transfer when possible. If the response has Content-Encoding: zstd, the body is transparently decompressed so the caller always receives raw (uncompressed) NAR bytes. NOTE: It's the caller responsibility to close the body.
func (*Cache) GetNarInfo ¶
GetNarInfo returns a parsed NarInfo from the cache server.
func (*Cache) GetPriority ¶
GetPriority returns the priority of this upstream cache.
func (*Cache) HasNar ¶ added in v0.0.20
func (c *Cache) HasNar(ctx context.Context, narURL nar.URL, mutators ...func(*http.Request)) (bool, error)
HasNar returns true if the NAR exists upstream.
func (*Cache) HasNarInfo ¶ added in v0.0.20
HasNarInfo returns true if the narinfo exists upstream.
func (*Cache) NarInfoExistence ¶
NarInfoExistence probes the upstream for the narinfo with a HEAD request and reports a definitive present/absent result, or unknown when the probe is inconclusive. The narinfo path (/<hash>.narinfo) is unambiguous, unlike the NAR path whose compression extension may differ from a CDC-normalized record.
func (*Cache) ParsePriority ¶ added in v0.3.0
ParsePriority parses the priority from the upstream.
func (*Cache) PublicKeys ¶
PublicKeys returns the parsed trusted public keys configured for this upstream cache. It returns an empty slice when none were configured.
func (*Cache) SetHealthy ¶ added in v0.3.0
SetHealthy sets the health status of the upstream.
func (*Cache) SetPriority ¶ added in v0.3.0
SetPriority sets the priority of the upstream.
type Existence ¶
type Existence int
Existence is a three-valued result of probing whether an asset exists upstream. Unlike HasNarInfo/HasNar (which collapse a timeout into "false"), it distinguishes a definitive not-found from an inconclusive (transient/timeout) probe so callers can safely act on genuine absence without mistaking a transient outage for it.
const ( // ExistenceUnknown means the probe was inconclusive (timeout, transport error, // or a non-404 error status). Callers MUST NOT treat this as absence. ExistenceUnknown Existence = iota // ExistencePresent means the upstream returned a success status. ExistencePresent // ExistenceAbsent means the upstream definitively returned not-found (404). ExistenceAbsent )
type NetrcCredentials ¶ added in v0.4.0
NetrcCredentials holds authentication credentials.
type Options ¶ added in v0.5.1
type Options struct {
// PublicKeys is a list of public keys for verifying signatures.
// If empty, signature verification will be skipped.
PublicKeys []string
// NetrcCredentials holds authentication credentials for the upstream cache.
// If nil, no authentication will be used.
NetrcCredentials *NetrcCredentials
// DialerTimeout is the timeout for establishing a TCP connection.
// If zero, defaults to defaultHTTPTimeout (3s).
DialerTimeout time.Duration
// ResponseHeaderTimeout is the timeout for waiting for the server's response headers.
// If zero, defaults to defaultHTTPTimeout (3s).
ResponseHeaderTimeout time.Duration
// Transport is the HTTP transport to use.
// If nil, a default transport will be created.
Transport http.RoundTripper
// RetryBackoff is the base delay before the first transient-error retry on
// idempotent requests; it doubles per attempt up to an internal cap. If zero,
// defaults to defaultRetryBackoff. Set a small value in tests to keep them fast.
RetryBackoff time.Duration
}
Options contains optional configuration for creating an upstream cache.