cfghttp

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2019 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrSession         strErr = "%s session: %v"
	ErrSessionAdvRefs  strErr = "%s session advertised references: %v"
	ErrPackDecode      strErr = "pack decode: %v"
	ErrPackScanAdvRefs strErr = "pack scan [1] advertised references: %v"

	ErrReceivePack       strErr = "bad receive pack: %v"
	ErrUploadPackRequest strErr = "bad upload pack: %v"
	ErrUploadPack        strErr = "bad upload pack: %v"

	ErrTransportEndpoint strErr = "repo [%s] endpoint invalid: %v"
	ErrNoServiceFound    strErr = "no service found"
	ErrEmptyHookData     strErr = "empty receive-pack hook data"
)

all provided errors

Variables

This section is empty.

Functions

func NewServer

func NewServer(gs GitServer, opts ...ServerOption) http.Handler

NewServer returns a new server object that can be used as a mux with the http.Handler

Types

type DebugLogger

type DebugLogger *logg.Logger

DebugLogger wrap *log.Loggers with this to display debug logging

type GitServer

type GitServer interface {
	NewInfoRefs(repoName string) InfoRefser
	NewReceivePack(repoName string) ReceivePacker
	NewUploadPack(repoName string) UploadPacker

	WithLogger(...interface{})
	WithPreReceiveHook(cfg.PreReceivePackHookFunc)
	WithPostReceiveHook(cfg.PostReceivePackHookFunc)
}

GitServer is the interface used to interact with the git server via HTTP

type GoGitServer

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

GoGitServer wraps concepts for go-git into a GitServer HTTP interface

func LoadGoGit

func LoadGoGit(m map[string]*git.Repository, endpoint string) *GoGitServer

LoadGoGit loads a mapping of git repositories (go-git) to a repository endpoint

func (*GoGitServer) NewInfoRefs

func (s *GoGitServer) NewInfoRefs(repoName string) InfoRefser

NewInfoRefs returns a new InfoRefs object to handle InfoRefs requests

func (*GoGitServer) NewReceivePack

func (s *GoGitServer) NewReceivePack(repoName string) ReceivePacker

NewReceivePack returns a new ReceivePack object

func (*GoGitServer) NewUploadPack

func (s *GoGitServer) NewUploadPack(repoName string) UploadPacker

NewUploadPack returns a new UploadPack object

func (*GoGitServer) WithLogger

func (s *GoGitServer) WithLogger(logger ...interface{})

WithLogger takes in logger/s to display debug and info logs for the GoGitServer object

func (*GoGitServer) WithPostReceiveHook

func (s *GoGitServer) WithPostReceiveHook(fn cfg.PostReceivePackHookFunc)

WithPostReceiveHook sets the post-receive hook for receive-pack requests

func (*GoGitServer) WithPreReceiveHook

func (s *GoGitServer) WithPreReceiveHook(fn cfg.PreReceivePackHookFunc)

WithPreReceiveHook sets the pre-receive hook for receive-pack requests

type InfoLogger

type InfoLogger *logg.Logger

InfoLogger wrap *log.Loggers with this to display info logging

type InfoRefs

type InfoRefs struct {
	*GoGitServer
	// contains filtered or unexported fields
}

InfoRefs holds all of the data needed to handle the git interface for info-ref requests

func (*InfoRefs) DoHTTP

func (ir *InfoRefs) DoHTTP(w http.ResponseWriter, r *http.Request) InfoRefser

DoHTTP takes in a HTTP request and decodes what is supposed to happen if there are any errors then this method is skipped, and errors can be checked with the Err() method

func (*InfoRefs) Err

func (ir *InfoRefs) Err() error

Err return any errors

type InfoRefser

type InfoRefser interface {
	DoHTTP(http.ResponseWriter, *http.Request) InfoRefser
	Err() error
}

InfoRefser returns HTTP requests for '/info/ref'

type ReceivePack

type ReceivePack struct {
	*GoGitServer
	// contains filtered or unexported fields
}

ReceivePack holds all of the data needed to handle the git interface for receive-pack requests through HTTP

func (*ReceivePack) Cleanup

func (rp *ReceivePack) Cleanup()

Cleanup takes any functions that were collected and runs them. This is for deferred processes

func (*ReceivePack) DoHTTP

DoHTTP takes in a HTTP request and decodes what is supposed to happen if there are any errors then this method is skipped, and errors can be checked with the Err() method

func (*ReceivePack) Err

func (rp *ReceivePack) Err() error

Err returns the error that was collected during the receive-pack processing

type ReceivePacker

type ReceivePacker interface {
	DoHTTP(http.ResponseWriter, *http.Request) ReceivePacker
	Cleanup()
	Err() error
}

ReceivePacker returns HTTP requests for '/receive-pack'

type Server

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

Server holds the handlers, middleware and mux for requests that the git client can make via HTTP

func (*Server) InfoRefsHandler

func (s *Server) InfoRefsHandler(w http.ResponseWriter, r *http.Request)

InfoRefsHandler handles HTTP requests for 'info-refs/'

func (*Server) ReceivePackHandler

func (s *Server) ReceivePackHandler(w http.ResponseWriter, r *http.Request)

ReceivePackHandler handles HTTP requests for 'receive-pack/'

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves the internal muxer for the http handler

func (*Server) UploadPackHandler

func (s *Server) UploadPackHandler(w http.ResponseWriter, r *http.Request)

UploadPackHandler handles HTTP requests for 'upload-pack/'

type ServerOption

type ServerOption func(*Server)

ServerOption provides functional options for Server objects in cfghttp

func WithLogger

func WithLogger(logger ...interface{}) ServerOption

WithLogger adds a logger to the library. If *log.Logger is used then both debug and info logs will be displayed. Wrap a *log.Logger in DebugLogger or InfoLogger to display just the logs for one level.

func WithMiddleware

func WithMiddleware(wares ...func(http.Handler) http.Handler) ServerOption

WithMiddleware adds any middleware to the HTTP server (i.e. can be used for auth)

func WithPathPrefix

func WithPathPrefix(prefix string) ServerOption

WithPathPrefix adds a http path prefix before any of the http path patterns

func WithPostReceiveHook

func WithPostReceiveHook(fn func(io.Writer, *cfg.PostReceivePackHookData)) ServerOption

WithPostReceiveHook adds a post-receive hook to the handler. Return a nil error to indicate post-receive hook success. Return a non-nil error to reject the post-receive hook. (Note the limitation of pre-receive hooks at: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks#_code_post_receive_code)

func WithPreReceiveHook

WithPreReceiveHook adds a pre-receive hook to the handler. Return a nil error to indicate pre-receive hook success. Return a non-nil error to reject the pre-receive hook. (Note the limitation of pre-receive hooks at: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks#_code_pre_receive_code)

type UploadPack

type UploadPack struct {
	*GoGitServer
	// contains filtered or unexported fields
}

UploadPack holds all of the data needed to handle the git interface for upload-pack requests for HTTP

func (*UploadPack) Cleanup

func (up *UploadPack) Cleanup()

Cleanup takes any functions that were collected and runs them. This is for deferred processes

func (*UploadPack) DoHTTP

DoHTTP takes in a HTTP request and decodes what is supposed to happen if there are any errors then this method is skipped, and errors can be checked with the Err() method

func (*UploadPack) Err

func (up *UploadPack) Err() error

Err returns the error that was collected during the upload-pack processing

type UploadPacker

type UploadPacker interface {
	DoHTTP(http.ResponseWriter, *http.Request) UploadPacker
	Cleanup()
	Err() error
}

UploadPacker returns HTTP requests for '/upload-pack'

Jump to

Keyboard shortcuts

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