@@ -28,12 +28,29 @@ var ErrServerClosed = errors.New("server closed")
2828// DefaultBackend is the default global Git transport server handler.
2929var DefaultBackend Handler = NewBackend (nil )
3030
31+ // ServerContextKey is the context key used to store the server in the context.
32+ var ServerContextKey = & contextKey {"git-server" }
33+
34+ // Handler is the interface that handles TCP requests for the Git protocol.
35+ type Handler interface {
36+ // ServeTCP handles a TCP connection for the Git protocol.
37+ ServeTCP (ctx context.Context , c io.ReadWriteCloser , req * packp.GitProtoRequest )
38+ }
39+
3140// NewBackend creates a [Handler] backed by the given [transport.Loader].
3241// If loader is nil, [transport.DefaultLoader] is used.
3342func NewBackend (loader transport.Loader ) Handler {
3443 return & backendHandler {b : backend .New (loader )}
3544}
3645
46+ // HandlerFunc is a function that implements the Handler interface.
47+ type HandlerFunc func (ctx context.Context , c io.ReadWriteCloser , req * packp.GitProtoRequest )
48+
49+ // ServeTCP implements the Handler interface.
50+ func (f HandlerFunc ) ServeTCP (ctx context.Context , c io.ReadWriteCloser , req * packp.GitProtoRequest ) {
51+ f (ctx , c , req )
52+ }
53+
3754// backendHandler wraps a [backend.Backend] to implement the [Handler] interface.
3855type backendHandler struct {
3956 b * backend.Backend
@@ -47,23 +64,6 @@ func (bh *backendHandler) ServeTCP(ctx context.Context, c io.ReadWriteCloser, re
4764 }
4865}
4966
50- // ServerContextKey is the context key used to store the server in the context.
51- var ServerContextKey = & contextKey {"git-server" }
52-
53- // Handler is the interface that handles TCP requests for the Git protocol.
54- type Handler interface {
55- // ServeTCP handles a TCP connection for the Git protocol.
56- ServeTCP (ctx context.Context , c io.ReadWriteCloser , req * packp.GitProtoRequest )
57- }
58-
59- // HandlerFunc is a function that implements the Handler interface.
60- type HandlerFunc func (ctx context.Context , c io.ReadWriteCloser , req * packp.GitProtoRequest )
61-
62- // ServeTCP implements the Handler interface.
63- func (f HandlerFunc ) ServeTCP (ctx context.Context , c io.ReadWriteCloser , req * packp.GitProtoRequest ) {
64- f (ctx , c , req )
65- }
66-
6767// Server is a TCP server that handles Git protocol requests.
6868type Server struct {
6969 // Addr is the address to listen on. If empty, it defaults to ":9418".
0 commit comments