package module
v0.3.0 Latest Latest

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

Go to latest
Published: Jul 25, 2022 License: MIT Imports: 7 Imported by: 0



Go Package Mapping


I personally use a lot of nice libraries in Go, but every time I start a new project I have to go hunting for import paths again!

Enter GPM, a glorified mapping of simple names to go-get imports.

For example, I use urfave/cli for all of my CLI projects. I've used it enough times to remember the import path, but let's say I didn't.
Using either a GPM server or local config, I can instead gpm get cli which finds cli in my map and runs go get

  • add - Add a local package
  • remove - Remove a local package
  • list - List local packages
  • config - Change local configuration
  • get - Get a list of packages
    • e.g. gpm get zerolog survey bbolt cli chi to get all the modules needed for gpm itself (assuming the map resolves to the same packages)
  • server - Start a gpm server

gpm will call out to a gpm server to find a package.
This makes it much simpler to have a central library of packages rather than exporting and importing between environments.

Want to run your own server? It's very easy! This CLI comes packaged with the server inside, simply run gpm server to start up a GPM server.
Remember to set a --token!
Put it behind your favorite reverse proxy, and it's ready to go!






View Source
const (
	DefaultServer = ""
	TokenHeader   = "X-GPM-Token"


This section is empty.


This section is empty.


type Client

type Client struct {
	// contains filtered or unexported fields

Client is a gpm client

func New

func New(token string, opts ...ClientOption) *Client

New returns a new Client

func (*Client) Add

func (c *Client) Add(ctx context.Context, pkg Package) error

Add adds a new Package to a gpm server

func (*Client) Get

func (c *Client) Get(ctx context.Context, name string) (Package, error)

Get gets a Package from a server

func (*Client) Info

func (c *Client) Info(ctx context.Context) (Info, error)

Info gets Info from a gpm server

func (*Client) Remove

func (c *Client) Remove(ctx context.Context, pkg Package) error

Remove removes a Package from a gpm server

func (*Client) Update

func (c *Client) Update(ctx context.Context, pkg Package) error

Update updates a Package on a gpm server

type ClientOption

type ClientOption func(*Client)

ClientOption is an option for a Client

func WithHTTP

func WithHTTP(client *http.Client) ClientOption

WithHTTP sets the http.Client for a Client

func WithServer

func WithServer(server string) ClientOption

WithServer sets the gpm server for a Client

type Info

type Info struct {
	Version     string    `json:"version"`
	NumPackages int       `json:"num_packages"`
	Packages    []Package `json:"packages"`

Info is gpm information, such as version and list of packages

type Package

type Package struct {
	Name   string `json:"name"`
	Import string `json:"import"`

Package is a gpm package


Path Synopsis
go-gpm module

Jump to

Keyboard shortcuts

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