Documentation
¶
Overview ¶
Package gitcache serves Git repositories read-only over smart HTTP from a local cache of bare repositories, refreshed from configured upstreams.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned when the upstream has no such repository. ErrNotFound = errors.New("repository not found upstream") // ErrRefused covers authentication failures and redirects. The cached // copy is not served after one, since the upstream may have withdrawn // access to it. ErrRefused = errors.New("upstream refused the request") // ErrTooLarge is returned for a repository larger than git.max_repo_size, // or than git.max_size where that is smaller. ErrTooLarge = errors.New("repository is larger than git.max_repo_size or git.max_size") // ErrCacheFull is returned for a fetch cut off because repositories in // use take what git.max_size leaves. ErrCacheFull = errors.New("git cache is full") )
var ErrRequestTooLarge = errors.New("request body too large")
ErrRequestTooLarge is returned by ReadRequest for a body past the limit.
Functions ¶
func UpstreamDir ¶
UpstreamDir names the top-level cache directory of the upstream called name at baseURL. It includes a hash of the URL, so repointing an upstream starts a fresh cache rather than serving the old host's repositories.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is the Git repository cache. internal/handler serves it at /git.
func (*Cache) Close ¶
Close stops the refreshes in progress and waits for them to finish, so none is still writing to the cache when it returns, then stops the relay. Fetches by ID run on request goroutines; stop the HTTP server first. Closing again does nothing.
type Lease ¶
type Lease struct {
// contains filtered or unexported fields
}
Lease is a use of a cached repository. The repository is not evicted until the lease is released.
func (*Lease) ServeInfoRefs ¶
func (l *Lease) ServeInfoRefs(w http.ResponseWriter, r *http.Request)
ServeInfoRefs answers GET info/refs?service=git-upload-pack.
func (*Lease) ServeUploadPack ¶
ServeUploadPack answers POST git-upload-pack with req, the request's body as ReadRequest read it. With OpenOptions.FetchWants, commits the request wants that the cache lacks are fetched from the upstream first.
type OpenOptions ¶
type OpenOptions struct {
// Refresh brings a cached repository up to date with the upstream first,
// or leaves it as it is when the upstream fails or is slow and the copy
// is recent enough (see Options).
Refresh bool
// FetchWants lets ServeUploadPack fetch commits a client asks for by ID
// that the cache lacks. Leave it off where a fetch by ID could reach
// commits the client may not read through this repository, such as
// GitHub forks with credentials configured.
FetchWants bool
}
OpenOptions says what Open does besides returning the repository.
type Options ¶
type Options struct {
CacheDir string
MaxSize int64
MaxRepoSize int64
RefreshWait time.Duration
StaleMaxAge time.Duration
// Client makes every upstream request, including those of the git
// processes the cache runs. Redirects are never followed.
Client *http.Client
Logger *slog.Logger
// Upstreams maps each configured upstream's name to its directory in
// CacheDir, as UpstreamDir names it. Only those directories are loaded
// at startup. A directory UpstreamDir would name for one of these names
// at another URL, left by repointing the upstream, is removed. Nothing
// else in CacheDir is touched, so it may hold other data.
Upstreams map[string]string
// contains filtered or unexported fields
}
Options configures a Cache.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request is the body of a POST git-upload-pack request, read in full before anything is started for it. Stateless requests are complete once sent, so a client that sends one slowly, or not at all, holds no upload-pack process and is bound by the server's read timeout.