Documentation
¶
Overview ¶
Package strategy provides a framework for implementing and registering different caching strategies.
Index ¶
- Variables
- func Register[Config any, S Strategy](r *Registry, id, description string, factory Factory[Config, S])
- func RegisterAPIV1(r *Registry)
- func RegisterArtifactory(r *Registry)
- func RegisterGitHubReleases(r *Registry, tokenManagerProvider githubapp.TokenManagerProvider)
- func RegisterHTTPProxy(r *Registry)
- func RegisterHermit(r *Registry)
- func RegisterHost(r *Registry)
- type APIV1
- type Artifactory
- type ArtifactoryConfig
- type Factory
- type GitHubReleases
- type GitHubReleasesConfig
- type HTTPProxy
- type Hermit
- type HermitConfig
- type Host
- type HostConfig
- type Interceptor
- type Mux
- type ProxyConfig
- type Registry
- type Strategy
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("strategy not found")
ErrNotFound is returned when a strategy is not found.
Functions ¶
func Register ¶
func Register[Config any, S Strategy](r *Registry, id, description string, factory Factory[Config, S])
Register a new proxy strategy.
func RegisterAPIV1 ¶
func RegisterAPIV1(r *Registry)
func RegisterArtifactory ¶
func RegisterArtifactory(r *Registry)
func RegisterGitHubReleases ¶
func RegisterGitHubReleases(r *Registry, tokenManagerProvider githubapp.TokenManagerProvider)
func RegisterHTTPProxy ¶
func RegisterHTTPProxy(r *Registry)
RegisterHTTPProxy registers a caching HTTP proxy strategy. It intercepts absolute-form proxy requests (e.g. from sdkmanager with --proxy_host / --proxy_port) where the client sends:
GET http://dl.google.com/some/path HTTP/1.1
The request URI is upgraded to HTTPS and the response is fetched and cached. Only GET requests are intercepted; other methods are passed through.
func RegisterHermit ¶
func RegisterHermit(r *Registry)
func RegisterHost ¶
func RegisterHost(r *Registry)
Types ¶
type APIV1 ¶
type APIV1 struct {
// contains filtered or unexported fields
}
The APIV1 strategy represents v1 of the proxy API.
type Artifactory ¶
type Artifactory struct {
// contains filtered or unexported fields
}
The Artifactory Strategy forwards all GET requests to the specified Artifactory instance, caching the response payloads.
Key features: - Sets X-JFrog-Download-Redirect-To header to prevent redirects - Passes through authentication headers - Supports both host-based and path-based routing simultaneously.
func NewArtifactory ¶
func NewArtifactory(ctx context.Context, config ArtifactoryConfig, cache cache.Cache, mux Mux) (*Artifactory, error)
func (*Artifactory) String ¶
func (a *Artifactory) String() string
type ArtifactoryConfig ¶
type ArtifactoryConfig struct {
Target string `hcl:"target,label" help:"The target Artifactory URL to proxy requests to."`
Hosts []string `hcl:"hosts,optional" help:"List of hostnames to accept for host-based routing. If empty, uses path-based routing only."`
}
ArtifactoryConfig represents the configuration for the Artifactory strategy.
In HCL it looks something like this:
artifactory "https://example.jfrog.io" {
hosts = ["maven.example.com", "npm.example.com"]
}
When hosts are configured, the strategy supports both host-based routing (clients connect to maven.example.com) and path-based routing (clients connect to /example.jfrog.io). Both modes share the same cache.
type GitHubReleases ¶
type GitHubReleases struct {
// contains filtered or unexported fields
}
The GitHubReleases strategy fetches private (and public) release binaries from GitHub.
func NewGitHubReleases ¶
func NewGitHubReleases(ctx context.Context, config GitHubReleasesConfig, cache cache.Cache, mux Mux, tokenManagerProvider githubapp.TokenManagerProvider) (*GitHubReleases, error)
NewGitHubReleases creates a Strategy that fetches private (and public) release binaries from GitHub.
func (*GitHubReleases) String ¶
func (g *GitHubReleases) String() string
type GitHubReleasesConfig ¶
type HTTPProxy ¶
type HTTPProxy struct {
// contains filtered or unexported fields
}
HTTPProxy is a caching HTTP proxy strategy that handles standard HTTP proxy requests in absolute form (GET http://host/path HTTP/1.1).
It implements the Interceptor interface rather than registering on the mux directly, so that absolute-form request detection happens before ServeMux route matching. This prevents overlap with more-specific routes such as /api/v1/ or /admin/ when the proxied upstream path happens to match them.
func NewHTTPProxy ¶
type Hermit ¶
type Hermit struct {
// contains filtered or unexported fields
}
Hermit caches Hermit package downloads. Acts as a smart router: GitHub releases redirect to github-releases strategy, all other sources are handled directly.
type HermitConfig ¶
type HermitConfig struct {
GitHubBaseURL string `hcl:"github-base-url" help:"Base URL for GitHub release redirects" default:"http://127.0.0.1:8080/github.com"`
}
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
The Host Strategy forwards all GET requests to the specified host, caching the response payloads.
type HostConfig ¶
type HostConfig struct {
Target string `hcl:"target,label" help:"The target URL to proxy requests to."`
Headers map[string]string `hcl:"headers,optional" help:"Headers to add to upstream requests."`
}
HostConfig represents the configuration for the Host strategy.
In HCL it looks something like this:
host {
target = "https://github.com/"
}
In this example, the strategy will be mounted under "/github.com".
type Interceptor ¶
type Interceptor interface {
Strategy
// Intercept wraps next, returning a handler that intercepts matching
// requests and delegates all others to next.
Intercept(next http.Handler) http.Handler
}
Interceptor is an optional interface a Strategy may implement to intercept incoming HTTP requests before ServeMux route matching. This is necessary for strategies like the HTTP proxy that need to inspect r.RequestURI rather than r.URL.Path — registering a "/" catch-all on the mux is insufficient because more-specific routes (e.g. /api/v1/) still win for overlapping paths.
type ProxyConfig ¶
type ProxyConfig struct{}
ProxyConfig holds configuration for the HTTP proxy strategy. Currently no options are required.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func NewRegistry() *Registry