gopath

package module
v0.0.0-...-0a07d09 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2017 License: MIT Imports: 3 Imported by: 2

README

gopath

gopath returns the current user's GOPATH, compatible with Go 1.8+ That is, it returns the value of the environment variable GOPATH, and if that is not set, the directory named go in the user's home directory.

What "home directory" means is platform-specific. gopath uses mitchellh/go-homedir to find out what the user's home directory is.

Example

package main

import (
	"fmt"
	"log"

	"github.com/thomasheller/gopath"
)

func main() {
	p, err := gopath.Get()
	if err != nil {
		log.Fatalf("Error getting GOPATH: %v", err)
	}

	fmt.Println(p)

	// Output:
	// /home/user/go (or whatever GOPATH is set)
}

For convenience, gopath also provides a function to join the GOPATH with one or more path elements, like filepath.Join:

package main

import (
	"fmt"
	"log"

	"github.com/thomasheller/gopath"
)

func main() {
	p, err := gopath.Join("src/github.com/thomasheller/gopath")
	if err != nil {
		log.Fatalf("Error getting GOPATH: %v", err)
	}

	fmt.Println(p)

	// Output:
	// /home/user/go/src/github.com/thomasheller/gopath (or whatever GOPATH is set)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get() (string, error)

Get returns the user's GOPATH, compatible with Go 1.8+. That is, it returns the value of the environment variable GOPATH, and if that is not set, the directory named "go" in the user's home directory.

func Join

func Join(elem ...string) (string, error)

Join returns the user's GOPATH plus one or more path elements joined with the GOPATH. This works just like filepath.Join.

Types

This section is empty.

Jump to

Keyboard shortcuts

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