Documentation
¶
Overview ¶
Package fetch implements a read-through HTTPS artefact cache for direct downloads.
Index ¶
- Variables
- type CachedResource
- type Handler
- type HandlerOption
- func WithAllowedHosts(hosts []string) HandlerOption
- func WithDownloader(dl *download.Downloader) HandlerOption
- func WithGitHubReleaseHost(host string) HandlerOption
- func WithGitHubReleaseRedirectHosts(hosts ...string) HandlerOption
- func WithHTTPClient(client *http.Client) HandlerOption
- func WithLogger(logger *slog.Logger) HandlerOption
- type Index
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound indicates the upstream resource was not found.
Functions ¶
This section is empty.
Types ¶
type CachedResource ¶
type CachedResource struct {
UpstreamURL string `json:"upstream_url"`
BlobHash string `json:"blob_hash"`
Size int64 `json:"size"`
ContentType string `json:"content_type,omitempty"`
ContentEncoding string `json:"content_encoding,omitempty"`
ContentDisposition string `json:"content_disposition,omitempty"`
ETag string `json:"etag,omitempty"`
LastModified string `json:"last_modified,omitempty"`
CachedAt time.Time `json:"cached_at"`
}
CachedResource stores metadata about a cached upstream download.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves cached direct-download artefacts.
func NewHandler ¶
func NewHandler(index *Index, store store.Store, opts ...HandlerOption) *Handler
NewHandler creates a new fetch handler.
func (*Handler) ServeGitHubRelease ¶
func (h *Handler) ServeGitHubRelease(w http.ResponseWriter, r *http.Request)
ServeGitHubRelease handles /github-release/{owner}/{repo}/releases/download/... requests.
type HandlerOption ¶
type HandlerOption func(*Handler)
HandlerOption configures a Handler.
func WithAllowedHosts ¶
func WithAllowedHosts(hosts []string) HandlerOption
WithAllowedHosts sets the allowlist for the generic /fetch route.
func WithDownloader ¶
func WithDownloader(dl *download.Downloader) HandlerOption
WithDownloader sets the shared singleflight downloader.
func WithGitHubReleaseHost ¶
func WithGitHubReleaseHost(host string) HandlerOption
WithGitHubReleaseHost overrides the host used by the /github-release route. This is mainly useful for tests.
func WithGitHubReleaseRedirectHosts ¶
func WithGitHubReleaseRedirectHosts(hosts ...string) HandlerOption
WithGitHubReleaseRedirectHosts overrides the allowed redirect hosts for /github-release. This is mainly useful for tests.
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) HandlerOption
WithHTTPClient sets the HTTP client used for upstream fetches.
func WithLogger ¶
func WithLogger(logger *slog.Logger) HandlerOption
WithLogger sets the logger for the handler.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index manages the upstream URL -> blob mapping using metadb envelope storage.
func NewIndex ¶
func NewIndex(resources *metadb.EnvelopeIndex) *Index
NewIndex creates a new fetch index backed by the given envelope index.
func (*Index) Put ¶
func (idx *Index) Put(ctx context.Context, upstreamURL string, entry *CachedResource, opts metadb.PutOptions) error
Put stores a cached resource entry keyed by upstream URL.