goproxy

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2019 License: MIT Imports: 9 Imported by: 1

README

GoProxy middleware

Middleware for go modules proxy, inspired by https://github.com/goproxyio/goproxy

Usage

How to set up a middleware:

  1. Initiate router:
    r, err := goproxy.NewRouter()
    
  2. Add needed handlers via
    err := r.AddRoute(plugin)
    
    for example:
    regular, err := vcs.NewPlugin(cacheDir)
    if err != nil {
        log.Fatal(err)
    }
    if err := r.AddRoute("", regular); err != nil {
        log.Fatal(err)
    }
    
    this library currently supports vcs which is pretty much like regular go get (regular in the example), gitlab which works upon gitlab's v4 API and delegation to another go proxy, see source/...
  3. Generate middleware:
    var m http.Handler = goproxy.Middleware(r)
    
    Now you can use it in your HTTP server See examples/goproxy for details

Example

There's an example which supports regular go get-like module retrieval and gitlab.

  1. Build it:
    go build ./examples/goproxy
    
  2. Start it:
    ./goproxy -cache-dir . -gitlab https://gitlab.com/api/v4 -listen 0.0.0.0:8081
    
  3. Set up environment:
    export GO111MODULE=on
    export GOPROXY=http://<gitlab private token>@localhost:8081
    
    Remember, you must generate gitlab private token first otherwise gitlab may reject your requests

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetModInfo added in v1.0.0

func GetModInfo(req *http.Request, prefix string) (path string, suffix string, err error)

GetModInfo retrieves mod info from URL

func Middleware

func Middleware(r *Router, transportPrefix string, logger *zerolog.Logger) http.Handler

Middleware acts as go proxy with given router.

transportPrefix is a head part of URL path which refers to address of go proxy before the module info. For example,

if we serving go proxy at https://0.0.0.0:8081/goproxy/..., transportPrefix will be "/goproxy"

func PathEncoding added in v1.0.0

func PathEncoding(path string) (string, error)

PathEncoding returns go module encoded path

Types

type Module added in v1.0.0

type Module interface {
	// ModulePath returns the module path.
	ModulePath() string

	// Versions lists all known versions with the given prefix.
	// Pseudo-versions are not included.
	// Versions should be returned sorted in semver order
	// (implementations can use SortVersions).
	Versions(ctx context.Context, prefix string) (tags []string, err error)

	// Stat returns information about the revision rev.
	// A revision can be any identifier known to the underlying service:
	// commit hash, branch, tag, and so on.
	Stat(ctx context.Context, rev string) (*RevInfo, error)

	// GoMod returns the go.mod file for the given version.
	GoMod(ctx context.Context, version string) (data []byte, err error)

	// Zip returns file reader of ZIP file for the given version of the module
	Zip(ctx context.Context, version string) (file io.ReadCloser, err error)
}

Module represents go module: some VSC (git, mercurial, svn, etc), Gitlab, another Go modules proxy, etc

type Plugin added in v1.0.0

type Plugin interface {
	Module(req *http.Request, prefix string) (Module, error)
	Leave(source Module) error
	Close() error
	String() string
}

Plugin gives a way to get a source object for a request

type RevInfo added in v1.0.0

type RevInfo struct {
	Version string // version string
	Time    string // commit time

	// These fields are used for Stat of arbitrary rev,
	// but they are not recorded when talking about module versions.
	Name  string `json:"-"` // complete ID in underlying repository
	Short string `json:"-"` // shortened ID, for use in pseudo-version
}

RevInfo describes a single revision of a module source

type Router added in v1.0.0

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

Router routes to some plugin

func NewRouter added in v1.0.0

func NewRouter() (*Router, error)

NewRouter ...

func (*Router) AddRoute added in v1.0.0

func (r *Router) AddRoute(mask string, f Plugin) error

AddRoute add plugin for a given path mask

func (*Router) Factory added in v1.0.0

func (r *Router) Factory(path string) Plugin

Plugin returns plugin for given route

Directories

Path Synopsis
examples
internal
base
Package base defines shared basic pieces of the go command, in particular logging and the Command structure.
Package base defines shared basic pieces of the go command, in particular logging and the Command structure.
browser
Package browser provides utilities for interacting with users' browsers.
Package browser provides utilities for interacting with users' browsers.
bug
Package bug implements the “go bug” command.
Package bug implements the “go bug” command.
cache
Package cache implements a build artifact cache.
Package cache implements a build artifact cache.
cfg
Package cfg holds configuration shared by multiple parts of the go command.
Package cfg holds configuration shared by multiple parts of the go command.
clean
Package clean implements the “go clean” command.
Package clean implements the “go clean” command.
cmdflag
Package cmdflag handles flag processing common to several go tools.
Package cmdflag handles flag processing common to several go tools.
dirhash
Package dirhash defines hashes over directory trees.
Package dirhash defines hashes over directory trees.
doc
Package doc implements the “go doc” command.
Package doc implements the “go doc” command.
envcmd
Package envcmd implements the “go env” command.
Package envcmd implements the “go env” command.
fix
Package fix implements the “go fix” command.
Package fix implements the “go fix” command.
fmtcmd
Package fmtcmd implements the “go fmt” command.
Package fmtcmd implements the “go fmt” command.
generate
Package generate implements the “go generate” command.
Package generate implements the “go generate” command.
get
Package get implements the “go get” command.
Package get implements the “go get” command.
help
Package help implements the “go help” command.
Package help implements the “go help” command.
list
Package list implements the “go list” command.
Package list implements the “go list” command.
load
Package load loads packages.
Package load loads packages.
modcmd
Package modcmd implements the “go mod” command.
Package modcmd implements the “go mod” command.
modfetch/codehost
Package codehost defines the interface implemented by a code hosting source, along with support code for use by implementations.
Package codehost defines the interface implemented by a code hosting source, along with support code for use by implementations.
modget
Package modget implements the module-aware “go get” command.
Package modget implements the module-aware “go get” command.
module
Package module defines the module.Version type along with support code.
Package module defines the module.Version type along with support code.
mvs
Package mvs implements Minimal Version Selection.
Package mvs implements Minimal Version Selection.
objabi
Originally, Go object files were Plan 9 object files, but no longer.
Originally, Go object files were Plan 9 object files, but no longer.
par
Package par implements parallel execution helpers.
Package par implements parallel execution helpers.
run
Package run implements the “go run” command.
Package run implements the “go run” command.
semver
Package semver implements comparison of semantic version strings.
Package semver implements comparison of semantic version strings.
singleflight
Package singleflight provides a duplicate function call suppression mechanism.
Package singleflight provides a duplicate function call suppression mechanism.
str
Package str provides string manipulation utilities.
Package str provides string manipulation utilities.
test2json
Package test2json implements conversion of test binary output to JSON.
Package test2json implements conversion of test binary output to JSON.
testenv
Package testenv provides information about what functionality is available in different testing environments run by the Go team.
Package testenv provides information about what functionality is available in different testing environments run by the Go team.
tool
Package tool implements the “go tool” command.
Package tool implements the “go tool” command.
txtar
Package txtar implements a trivial text-based file archive format.
Package txtar implements a trivial text-based file archive format.
version
Package version implements the “go version” command.
Package version implements the “go version” command.
vet
Package vet implements the “go vet” command.
Package vet implements the “go vet” command.
web
Package web defines helper routines for accessing HTTP/HTTPS resources.
Package web defines helper routines for accessing HTTP/HTTPS resources.
plugin
vcs

Jump to

Keyboard shortcuts

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