git

package
v0.0.0-...-e308f56 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package git implements a protocol-aware Git caching proxy strategy.

Index

Constants

This section is empty.

Variables

View Source
var ErrSpoolFailed = errors.New("spool failed before response started")

ErrSpoolFailed is returned by ServeTo when the spool failed before any headers were written to the client, allowing the caller to fall back to upstream.

Functions

func ExtractRepoPath

func ExtractRepoPath(pathValue string) string

func Register

func Register(r *strategy.Registry, scheduler jobscheduler.Provider, cloneManagerProvider gitclone.ManagerProvider, tokenManagerProvider githubapp.TokenManagerProvider)

func SpoolKeyForRequest

func SpoolKeyForRequest(pathValue string, r *http.Request) (string, error)

SpoolKeyForRequest returns the spool key for a request, or empty string if the request is not spoolable. For POST requests, the body is hashed to differentiate protocol v2 commands (e.g. ls-refs vs fetch) that share the same URL. The request body is buffered and replaced so it can still be read by the caller.

Types

type Config

type Config struct {
	SnapshotInterval       time.Duration `` /* 127-byte string literal not displayed */
	MirrorSnapshotInterval time.Duration `` /* 159-byte string literal not displayed */
	RepackInterval         time.Duration `hcl:"repack-interval,optional" help:"How often to run full repack. 0 disables." default:"0"`
	ZstdThreads            int           `hcl:"zstd-threads,optional" help:"Threads for zstd compression/decompression (0 = all CPU cores)." default:"0"`
}

type RepoSpools

type RepoSpools struct {
	// contains filtered or unexported fields
}

RepoSpools manages all response spools for a single repository.

func NewRepoSpools

func NewRepoSpools(dir string) *RepoSpools

func (*RepoSpools) Close

func (rp *RepoSpools) Close() error

Close marks the repo spools as closed, waits for all readers to finish, and removes spool files from disk.

func (*RepoSpools) GetOrCreate

func (rp *RepoSpools) GetOrCreate(key string) (spool *ResponseSpool, isWriter bool, err error)

GetOrCreate returns an existing spool for the key, or creates a new one. isWriter is true if the caller created the spool and should act as the writer.

type ResponseSpool

type ResponseSpool struct {
	// contains filtered or unexported fields
}

ResponseSpool captures a single HTTP response (headers + body) to a file on disk, allowing one writer and multiple concurrent readers. Readers follow the writer, blocking when caught up until the write completes.

func NewResponseSpool

func NewResponseSpool(filePath string) (*ResponseSpool, error)

func (*ResponseSpool) CaptureHeader

func (rs *ResponseSpool) CaptureHeader(status int, header http.Header)

func (*ResponseSpool) Failed

func (rs *ResponseSpool) Failed() bool

func (*ResponseSpool) MarkComplete

func (rs *ResponseSpool) MarkComplete()

func (*ResponseSpool) MarkError

func (rs *ResponseSpool) MarkError(err error)

func (*ResponseSpool) ServeTo

func (rs *ResponseSpool) ServeTo(w http.ResponseWriter) error

ServeTo streams the spooled response to w, blocking when caught up to the writer.

func (*ResponseSpool) WaitForReaders

func (rs *ResponseSpool) WaitForReaders()

WaitForReaders blocks until all active spool readers have finished.

func (*ResponseSpool) Write

func (rs *ResponseSpool) Write(data []byte) error

type SpoolTeeWriter

type SpoolTeeWriter struct {
	// contains filtered or unexported fields
}

SpoolTeeWriter wraps an http.ResponseWriter to capture the response into a spool while simultaneously streaming it to the original client.

func NewSpoolTeeWriter

func NewSpoolTeeWriter(inner http.ResponseWriter, spool *ResponseSpool) *SpoolTeeWriter

NewSpoolTeeWriter creates a new SpoolTeeWriter that tees writes to both the inner ResponseWriter and the given spool.

func (*SpoolTeeWriter) Flush

func (w *SpoolTeeWriter) Flush()

func (*SpoolTeeWriter) Header

func (w *SpoolTeeWriter) Header() http.Header

func (*SpoolTeeWriter) Write

func (w *SpoolTeeWriter) Write(data []byte) (int, error)

func (*SpoolTeeWriter) WriteHeader

func (w *SpoolTeeWriter) WriteHeader(code int)

type Strategy

type Strategy struct {
	// contains filtered or unexported fields
}

func New

func New(
	ctx context.Context,
	config Config,
	schedulerProvider jobscheduler.Provider,
	cache cache.Cache,
	mux strategy.Mux,
	cloneManagerProvider gitclone.ManagerProvider,
	tokenManagerProvider githubapp.TokenManagerProvider,
) (*Strategy, error)

func (*Strategy) SetHTTPTransport

func (s *Strategy) SetHTTPTransport(t http.RoundTripper)

SetHTTPTransport overrides the HTTP transport used for upstream requests. This is intended for testing.

func (*Strategy) String

func (s *Strategy) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL