gomods

package module
v0.2.0 Latest Latest
Warning

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

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

README

Gomods

Caddy plugin that provides a caching Go modules proxy with your own domain.

state release license

NOTE: This is a beta release, we do not consider it completely production ready yet. Use at your own risk.

Gomods is a Caddy plugin that provides a caching Go modules proxy with your own domain. It supports all the hosting services and VCS` that are supported by Go tools. It also provides local caching and parallel workers to fetch and store Go modules.

Using Gomods

Note: The master branch is using Caddy v2, if you want to use Gomods with previous Caddy versions, check the caddy-v1 branch.

Gomods uses Go tools in the background for fetching the modules so there needs to be an installed version of Go on your machine.

For installing Gomods run the following command:

go get go.okkur.org/gomods/cmd/gomods

Then you should create a config file like this example:

gomods.test {
  gomods
}

The example above uses the default values for Go binary and number of parallel workers. To customize these values add these fields to your config file:

gomods.test {
  gomods {
    gobinary /usr/bin/go
    workers 2
  }
}

To enable caching you should also add the cache field to the config:

gomods.test {
  gomods {
    cache
  }
}

Just like gomods itself, cache also uses its default values when not provided. You can specify fields like type and path to customize caching:

gomods.test {
  gomods {
    cache {
      type local
      path /home/user/gomods_cache
    }
  }
}

For more information about the configuration options and the JSON config example, check the Configuration page.

To run Gomods run the following command in the same directory that the config file is located:

$ gomods start

Support

For detailed information on support options see our support guide.

Helping out

Best place to start is our contribution guide.


Code is licensed under the Apache License, Version 2.0.
Documentation/examples are licensed under Creative Commons BY-SA 4.0.
Illustrations, trademarks and third-party resources are owned by their respective party and are subject to different licensing.


Copyright 2019 - The Gomods authors

Documentation

Index

Constants

View Source
const (
	// DefaultGomodsCacheType is the default cache mode
	DefaultGomodsCacheType = "tmp"
	// DefaultGomodsWorkers is the default number of parallel workers
	DefaultGomodsWorkers = 1
)

Variables

View Source
var DefaultGoBinaryPath = os.Getenv("GOROOT") + "/bin/go"

DefaultGoBinaryPath is the default Golang binary installed on the machine

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Enable bool
	Type   string `json:"type,omitempty"`
	Path   string `json:"path,omitempty"`
}

func (*Cache) ParseCache

func (cache *Cache) ParseCache(d *caddyfile.Dispenser) error

ParseCache parses the txtdirect config for gomods cache

type Config

type Config struct {
	GoBinary string `json:"gobinary,omitempty"`
	Workers  int    `json:"workers,omitempty"`
	Cache    Cache  `json:"cache,omitempty"`
	// contains filtered or unexported fields
}

func (*Config) ParseGomods

func (conf *Config) ParseGomods(d *caddyfile.Dispenser) error

ParseGomods parses the txtdirect config for gomods

func (*Config) Serve

func (conf *Config) Serve(w http.ResponseWriter, r *http.Request) error

Serve handles the incoming requests and serves the module files like .mod and etc

func (*Config) SetDefaults

func (conf *Config) SetDefaults()

SetDefaults sets the default values for gomods config if the fields are empty

type Gomods

type Gomods struct {
	Config Config
}

func (Gomods) CaddyModule added in v0.2.0

func (Gomods) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (Gomods) ServeHTTP

func (g Gomods) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error

ServeHTTP implements caddyhttp.MiddlewareHandler.

func (*Gomods) UnmarshalCaddyfile added in v0.2.0

func (g *Gomods) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile implements caddyfile.Unmarshaler.

type Module

type Module struct {
	Name    string
	Version string
	FileExt string
}

Module is the struct that keeps a Go module's data

func (*Module) DecodeImportPath

func (m *Module) DecodeImportPath() error

DecodeImportPath decodes the module's import path. For more information check https://github.com/golang/go/blob/master/src/cmd/go/internal/module/module.go#L375-L433

func (*Module) ParseImportPath

func (m *Module) ParseImportPath(path string) error

ParseImportPath parses the request path and exports the module's import path, module's version and file extension

type ModuleHandler

type ModuleHandler interface {
	// contains filtered or unexported methods
}

ModuleHandler is the interface that keeps the module handlers for fething and caching

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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