githttp

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2016 License: Apache-2.0, Apache-2.0 Imports: 13 Imported by: 0

README

go-git-http

A Smart Git Http server library in Go (golang)

Example
package main

import (
    "log"
    "net/http"

    "github.com/AaronO/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/AaronO/go-git-http"
    "github.com/AaronO/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

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 {
	// Underlaying reader (to relay calls to)
	io.ReadCloser

	// 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 {
	// Underlaying reader (to relay calls to)
	io.ReadCloser

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

	// List of events RpcReader has picked up through scanning
	// these events do not contain the "Dir" attribute
	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)

Implement 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