gilo

package module
v0.0.0-...-18867cc Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2016 License: MIT Imports: 10 Imported by: 0

README

gilo for golang Build Status

Simple Program for setting GOPATH, inspired by rbenv

Intelligently sets up your GOPATH and other golang environment variables.

Usage

automatically hooks into standard go commands i.e go get, go build, go env, etc. additional shims can be made to work with other programs (see installation)

Integrating with gilo

gilo provides a http daemon that can be run and requested for environments for paths. It returns json payloads describing the golang environment for the specified path.

# Default port is 8081
gilod -port=8081 &
curl http://localhost:8081/abs/path/to/directory

Installation (downloads)

Currently only support binary builds for linux,osx 386 and amd64. No support for windows as I don't have a test box, should be fairly easy to add support later.

latest release

export RELEASE=0.0.1-linux-amd64
wget https://bitbucket.org/jatone/gilo/downloads/gilo-$RELEASE.tgz
tar xf gilo-$RELEASE.tgz --directory $HOME

# Export bin directory to your path. (or link into the path)
export PATH=$HOME/.gilo/bin:$PATH

# Creating shims
# this will place symlinks to the provided set of programs
# inside of $HOME/.gilo/bin
gilo shim go atom glide
latest (development version)
GOPATH=$HOME/.gilo go get bitbucket.org/jatone/gilo/commands/...

# Export bin directory to your path. (or link into the path)
export PATH=$HOME/.gilo/bin:$PATH

# Creating shims
# this will place symlinks to the provided set of programs
# inside of $HOME/.gilo/bin
gilo shim go atom glide

How it works

gilo searches the current directory and its parents for a .gopath marker file and then executes the command and arguments passed to it with the GOPATH and PATH arguments modified.

Configuration

# See relevant golang documentation for each environment variable.
goroot: "/home/user/.golang/go"
gobin: "/home/user/.local/programs/bin"
gotooldir: "home/user/.golang/tools"
gorace: "log_path=/tmp/race/report strip_path_prefix=/my/go/sources/"
gogccflags: "-fPIC -m64 -pthread -fmessage-length=0"
# gopaths are special in that they are appended to the GOPATH environment variable.
# where as the .gopath directory is prepended. example:
# .gopath resides in /home/soandso/development/project1
# echo $GOPATH is /home/soandso/.golang/lib
# and .gopath contains the array of additional gopaths
# - /home/soandso/development/project2
# the computed GOPATH would be:
# /home/soandos/development/project1:/home/soandso/.golang/lib:/home/soandso/development/project2
gopaths:
  - /home/user/development/project2

Examples

  1. create a .gopath file in the directory you want to use as the GOPATH gilo will search recursively up to root from your current directory.
$GOPATH
bash: /home/jatone/.golang: Is a directory
go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/shared/development/gilo:/home/jatone/.golang/lib"
GORACE=""
GOROOT="/home/jatone/.golang/go"
GOTOOLDIR="/home/jatone/.golang/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT=""
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
  1. if .gopath is not found it uses the default go env.
$GOPATH
bash: /home/jatone/.golang: Is a directory
go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jatone/.golang/lib"
GORACE=""
GOROOT="/home/jatone/.golang/go"
GOTOOLDIR="/home/jatone/.golang/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT=""
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

Debugging - use gilo env

gilo env --help
usage: gilo env [<path>...]

Display golang environment information for the supplied paths

Flags:
  --help     Show context-sensitive help (also try --help-long and --help-man).
  --version  Show application version.

Args:
  [<path>]  path to display golang environment, defaults to current directory
gilo env
2016/02/13 11:16:35 Golang Environment for: /shared/development/gilo
Default Go Environment:
GOROOT: /home/jatone/.golang/go
GOBIN:
GORACE:
GOTOOLDIR:
GOGCCFLAGS:
GOPATH: /home/jatone/.golang/lib
PATH: /home/jatone/.local/programs/bin:/home/jatone/.rbenv/shims:/home/jatone/.rbenv/bin:/home/jatone/.gilo/bin:/home/jatone/.golang/go/bin:/home/jatone/.golang/lib/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
Computed Go Environment:
GOROOT: /home/jatone/.golang/go
GOBIN:
GORACE:
GOTOOLDIR:
GOGCCFLAGS:
GOPATH: /shared/development/gilo:/home/jatone/.golang/lib
PATH: /home/jatone/.local/programs/bin:/home/jatone/.rbenv/shims:/home/jatone/.rbenv/bin:/home/jatone/.golang/go/bin:/home/jatone/.golang/lib/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl

Debugging multiple paths

gilo env path1 path2 path3
program output
same as gilo env but for each path.

invoke arbitrary command with gilo

gilo-shim mycommand commandargs...

Upcoming features:

  • be able to specify the file to search for along the directory path. this will enable setting different configurations for activities like cross compiling.

Documentation

Index

Constants

View Source
const ConfigFileName = ".gopath"

ConfigFileName - file name containing the gilo configuration.

View Source
const (
	// DefaultVersion used if version isn't set.
	DefaultVersion = "development"
)
View Source
const ShimBinaryName = "gilo-shim"

ShimBinaryName name of the shim binary name

Variables

Debug logger, defaults to discard

View Source
var ErrDuplicateBinaryDirectory = errors.New("found multiple instances of the gilo bin directory within the path")

ErrDuplicateBinaryDirectory - Usually indicates an environment problem and gilo may behave unexpectedly. For example infinite loops. Gilo Attempts to bypass this behaviour by stripping all occurrances of the gilo bin directory from the path, but if other binaries are installed at that location then they may not be properly resolved within the executed environment.

View Source
var NoopTransformer = ConfigTransformerFunc(func(c Config) (Config, error) {
	return c, nil
})

NoopTransformer - Does not make any changes to the configuration. Used for Tests.

View Source
var Version string

Version specified at build time using: `git describe --tags --long`

Functions

func GolangEnvForPath

func GolangEnvForPath(path string) (Environment, Environment, error)

GolangEnvForPath - Takes a path and returns the default and computed environments.

func PrintEnvironment

func PrintEnvironment(w io.Writer, env Environment) error

PrintEnvironment - Prints information about the specified environment to the writer.

Types

type Config

type Config struct {
	Goroot     string
	Gobin      string
	Gorace     string
	Gotooldir  string
	GoGCCFlags string
	Gopaths    []string
}

Config - Configuration for gilo. allows specifying various golang environment variables.

func ConfigFromEnvironment

func ConfigFromEnvironment(env Environment) Config

ConfigFromEnvironment - creates a config from the environment.

type ConfigTransformer

type ConfigTransformer interface {
	Transform(Config) (Config, error)
}

ConfigTransformer - Responsible for taking a base configuration and transforming it into another configuration. A ConfigTransformer should not return any updated values in the returned configuration if an error occurs. i.e. when an error occurs the input config should be equal to the output config.

func CompositeConfigTransformer

func CompositeConfigTransformer(transformers ...ConfigTransformer) ConfigTransformer

CompositeConfigTransformer - Takes a set of transformers and applies each one to the the input configuration. If any of the transformers fail, then the composite transformer fails immediately and returns the error.

func MustNewTransformers

func MustNewTransformers(path string) ConfigTransformer

MustNewTransformers - Panics if the delegated invocation of NewTransformers errors.

func NewConfigTransformerFromPath

func NewConfigTransformerFromPath(path string) ConfigTransformer

NewConfigTransformerFromPath - Creates a new configuration with default values from the specified path. Completely ignores the provided configuration.

func NewTransformers

func NewTransformers(giloconfigpath string) (ConfigTransformer, error)

NewTransformers - Generates the set of Configuration Transformers needed based on the provided filepath to a configuration file.

type ConfigTransformerFactory

type ConfigTransformerFactory struct {
	util.FileResolver
}

ConfigTransformerFactory - Builds a ConfigTransformer

func (ConfigTransformerFactory) Build

Build - Takes a path and returns either a ConfigTransformer or an error.

type ConfigTransformerFunc

type ConfigTransformerFunc func(Config) (Config, error)

ConfigTransformerFunc - Allows pure functions to act as ConfigTransformers.

func (ConfigTransformerFunc) Transform

func (t ConfigTransformerFunc) Transform(config Config) (Config, error)

Transform - Invokes the pure function on the specified configuration.

type Environment

type Environment struct {
	Goroot     string
	Gobin      string
	Gorace     string
	Gotooldir  string
	GoGCCFlags string
	Gopaths    []string
	Path       string // Path environment variable, we update it based on the golang configuration.
}

Environment - Specifies a golang environment.

func DefaultEnvironment

func DefaultEnvironment(options ...EnvironmentOption) Environment

DefaultEnvironment - Loads golang default environment from environment variables.

func NewEnvironment

func NewEnvironment(template Environment, options ...EnvironmentOption) Environment

NewEnvironment creates a new environment using the template and the options.

func (Environment) Gopath

func (t Environment) Gopath() string

Gopath - Returns the list seperated (:) gopath.

func (Environment) MungeEnvironment

func (t Environment) MungeEnvironment()

MungeEnvironment - munges the environment variables with updated values.

func (Environment) ReplaceWithGobinInPath

func (t Environment) ReplaceWithGobinInPath(pattern string) Environment

ReplaceWithGobinInPath - Replaces the first occurrance of the given string with the Environment's Gobin value.

func (Environment) StripFromPath

func (t Environment) StripFromPath(subpath string) Environment

StripFromPath - Updates the environment's Path by stripping the specified subpath from the path.

func (Environment) UpdateFromConfig

func (t Environment) UpdateFromConfig(config Config) Environment

UpdateFromConfig - Updates the environment using the specified configuration.

type EnvironmentComputer

type EnvironmentComputer struct {
	// DefaultEnv - the default golang environment, used as a base for
	// the computed golang environment.
	DefaultEnv Environment
	// Transformer - Applies transformations to the configuration.
	Transformer ConfigTransformer
	// GiloBinary - Returns the directory path where the gilo binary
	// is located, used to strip the binary from the environments path.
	// allowing gilo to act as a shim for various commands.
	GiloBinary util.BinaryResolver
}

EnvironmentComputer - Computes the default and configured golang environments.

func (EnvironmentComputer) Compute

Compute - Computes the default golang environment and the updated golang environment based on the provided resolver.

type EnvironmentOption

type EnvironmentOption func(*Environment)

EnvironmentOption specifies an option for the environment

func EnvironmentOptionGopath

func EnvironmentOptionGopath(paths ...string) EnvironmentOption

EnvironmentOptionGopath sets the gopaths for the environment

type YAMLConfig

type YAMLConfig struct {
	io.Reader
}

YAMLConfig - yaml based configuration.

func (YAMLConfig) Transform

func (t YAMLConfig) Transform(c Config) (Config, error)

Transform - Transforms the specified config based on the underlying yaml configuration.

Directories

Path Synopsis
commands
x

Jump to

Keyboard shortcuts

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