Documentation
¶
Overview ¶
Package backendutil holds the shared plumbing used by every platform backend under backends/. It exists to eliminate the copy-pasted HTTP-client, hook, retry, and base-URL construction that was previously duplicated (often byte-for-byte) across the seven backend packages.
These helpers are intentionally internal: they are an implementation detail of the backends and must not become part of the SDK's public API.
Index ¶
- Variables
- func ChainTransport(inner, outer http.RoundTripper) http.RoundTripper
- func ConvertHooks(h *provider.Hooks) *transport.Hooks
- func DefaultBaseURL(base, def string) string
- func HTTPTransport(skipTLS bool) http.RoundTripper
- func MapRetryConfig(rc *provider.RetryConfig) *transport.RetryConfig
- func NewScanLimitError(msg string) error
- func NormalizeBaseURL(base string) string
- func ResolveLabelID(scan LabelPageFunc, name string, maxPages, perPage int) (int64, error)
- func ToTransportLogger(l provider.Logger) transport.Logger
- type IDCache
- type LabelPageFunc
- type LabelRef
- type ScanLimitError
Constants ¶
This section is empty.
Variables ¶
var ErrLabelScanLimit = errors.New("label not found within scan limit")
ErrLabelScanLimit reports that the named label was not found within the scanned page budget. It is distinct from a definitive not-found: the label may exist beyond the limit, so callers surface it as a scan-limit error rather than a 404.
Functions ¶
func ChainTransport ¶
func ChainTransport(inner, outer http.RoundTripper) http.RoundTripper
ChainTransport chains two round trippers. The outer tripper is invoked first; if it returns a non-nil response or a non-nil error that result is returned, otherwise the inner transport (the underlying connection) handles the request.
func ConvertHooks ¶
ConvertHooks adapts provider.Hooks into transport.Hooks. The request-hook signatures differ across the two packages (provider.RequestHook returns a context; transport.RequestHook returns an error), so each request hook is wrapped to discard the returned context. Identical across all backends.
func DefaultBaseURL ¶
DefaultBaseURL returns base if non-empty, otherwise def.
func HTTPTransport ¶
func HTTPTransport(skipTLS bool) http.RoundTripper
HTTPTransport returns an http.RoundTripper honouring the skipTLS flag: the default transport when verification is enabled, or a transport that disables certificate verification when the caller has explicitly opted into SkipTLS.
func MapRetryConfig ¶
func MapRetryConfig(rc *provider.RetryConfig) *transport.RetryConfig
MapRetryConfig converts a provider.RetryConfig (which counts retries, i.e. attempts beyond the first) into a transport.RetryConfig (which counts total attempts), hence the +1. Returns nil for a nil input so callers can assign the result directly.
func NewScanLimitError ¶ added in v0.45.0
NewScanLimitError builds a ScanLimitError with the given message.
func NormalizeBaseURL ¶
NormalizeBaseURL returns base with a single trailing slash removed and a trailing "/api/v1" suffix removed. Used by Gitea/Forgejo-style backends whose SDKs add the version prefix themselves.
func ResolveLabelID ¶ added in v0.45.0
func ResolveLabelID(scan LabelPageFunc, name string, maxPages, perPage int) (int64, error)
ResolveLabelID scans pages for the named label and returns its ID, or ErrLabelScanLimit when the budget is exhausted or a short page is reached without a match. Scan errors propagate unchanged.
Types ¶
type IDCache ¶ added in v0.45.0
type IDCache struct {
// contains filtered or unexported fields
}
IDCache is a TTL cache from string keys to int64 IDs. Backends use it to memoize name→ID resolutions (labels, users) so repeated writes do not rescan. The zero value is not usable; construct with NewIDCache.
func NewIDCache ¶ added in v0.45.0
NewIDCache constructs an IDCache with the given TTL (TTL <= 0 never expires entries).
func (*IDCache) ResolveLabel ¶ added in v0.45.0
func (c *IDCache) ResolveLabel(key, name string, scan LabelPageFunc, maxPages, perPage int) (int64, error)
ResolveLabel resolves via ResolveLabelID and caches the result under key+"/"+name. Failures are not cached.
type LabelPageFunc ¶ added in v0.45.0
LabelPageFunc fetches one page of labels; page is 1-based, perPage is the requested page size, and a page returning fewer than perPage refs ends the scan.
type LabelRef ¶ added in v0.45.0
LabelRef is the minimal label shape the resolver needs from one platform page fetch.
type ScanLimitError ¶ added in v0.45.0
type ScanLimitError struct {
Msg string
}
ScanLimitError wraps ErrLabelScanLimit with a platform-specific message (errors.Is reports it as ErrLabelScanLimit). Callers that need to distinguish "not found within the scan budget" from other failures use errors.Is(err, backendutil.ErrLabelScanLimit).
func (*ScanLimitError) Error ¶ added in v0.45.0
func (e *ScanLimitError) Error() string
func (*ScanLimitError) Unwrap ¶ added in v0.45.0
func (e *ScanLimitError) Unwrap() error