githttp

package module
v0.0.0-...-270aab9 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

README

go-git-http

Build Status

An updated and fixed go-git-http library written in Go (golang) With Small fixes for multiplatform

Example
package main

import (
    "log"
    "net/http"

    "github.com/quaddimentional/go-git-http"
)

func main() {
    // Get git handler to serve a directory of repos
    git := githttp.New("/Users/aaron/git")

    // Attach handler to http server
    http.Handle("/", git)

    // Start HTTP server
    err := http.ListenAndServe(":8080", nil)
    if err != nil {
        log.Fatal("ListenAndServe: ", err)
    }
}
Authentication example
package main

import (
    "log"
    "net/http"

    "github.com/quaddimentional/go-git-http"
    "github.com/quaddimentional/go-git-http/auth"
)


func main() {
    // Get git handler to serve a directory of repos
    git := githttp.New("/Users/aaron/git")

    // Build an authentication middleware based on a function
    authenticator := auth.Authenticator(func(info auth.AuthInfo) (bool, error) {
        // Disallow Pushes (making git server pull only)
        if info.Push {
            return false, nil
        }

        // Typically this would be a database lookup
        if info.Username == "admin" && info.Password == "password" {
            return true, nil
        }

        return false, nil
    })

    // Attach handler to http server
    // wrap authenticator around git handler
    http.Handle("/", authenticator(git))

    // Start HTTP server
    err := http.ListenAndServe(":8080", nil)
    if err != nil {
        log.Fatal("ListenAndServe: ", err)
    }
}

Documentation

Index

Constants

View Source
const (
	TAG = iota + 1
	PUSH
	FETCH
	PUSH_FORCE
)

Possible event types

View Source
const VERSION = "1.0.0"

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorNoAccess

type ErrorNoAccess struct {
	// Path to directory of repo accessed
	Dir string
}

func (*ErrorNoAccess) Error

func (e *ErrorNoAccess) Error() string

type Event

type Event struct {
	// One of tag/push/fetch
	Type EventType `json:"type"`

	// SHA of commit
	Commit string `json:"commit"`

	// Path to bare repo
	Dir string

	////
	// Set for pushes or tagging
	////
	Tag    string `json:"tag,omitempty"`
	Last   string `json:"last,omitempty"`
	Branch string `json:"branch,omitempty"`

	// Error contains the error that happened (if any)
	// during this action/event
	Error error

	// Http stuff
	Request *http.Request
}

An event (triggered on push/pull)

type EventType

type EventType int

func (EventType) MarshalJSON

func (e EventType) MarshalJSON() ([]byte, error)

func (EventType) String

func (e EventType) String() string

func (EventType) UnmarshalJSON

func (e EventType) UnmarshalJSON(data []byte) error

type GitHttp

type GitHttp struct {
	// Root directory to serve repos from
	ProjectRoot string

	// Path to git binary
	GitBinPath string

	// Access rules
	UploadPack  bool
	ReceivePack bool

	// Event handling functions
	EventHandler func(ev Event)
}

func New

func New(root string) *GitHttp

Shorthand constructor for most common scenario

func (*GitHttp) Init

func (g *GitHttp) Init() (*GitHttp, error)

Build root directory if doesn't exist

func (*GitHttp) ServeHTTP

func (g *GitHttp) ServeHTTP(w http.ResponseWriter, r *http.Request)

Implement the http.Handler interface

type GitReader

type GitReader struct {
	// Underlying reader (to relay calls to)
	io.Reader

	// Error
	GitError error
}

GitReader scans for errors in the output of a git command

func (*GitReader) Read

func (g *GitReader) Read(p []byte) (n int, err error)

Implement the io.Reader interface

type HandlerReq

type HandlerReq struct {
	Rpc  string
	Dir  string
	File string
	// contains filtered or unexported fields
}

type RpcReader

type RpcReader struct {
	// Underlying reader (to relay calls to).
	io.Reader

	// Rpc type (receive-pack or upload-pack).
	Rpc string

	// List of events RpcReader has picked up through scanning.
	// These events do not have the Dir field set.
	Events []Event
	// contains filtered or unexported fields
}

RpcReader scans for events in the incoming rpc request data.

func (*RpcReader) Read

func (r *RpcReader) Read(p []byte) (n int, err error)

Read implements the io.Reader interface.

type Service

type Service struct {
	Method  string
	Handler func(HandlerReq) error
	Rpc     string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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