-
Notifications
You must be signed in to change notification settings - Fork 1
001. Go dev setup
Tanveer Alam edited this page Sep 17, 2019
·
2 revisions
GO Dev setup
GOPATH:
- lists places to look for go code also used to resolve go imports.
- default location:
$HOME/go -
$ go env GOPATH /home/tan/go
-
$ ls -1 $(go env GOPATH) bin pkg src -
src:- Holds the source code.
- Path below
srcdetermines the import path or executable name.
-
pkg:- Holds installed package objects.
- Each targeting os and arch has its own subdirectory of pkg (pkg/GOOS_GOARCH)
-
$ go env GOOS GOARCH linux amd64
- Suppose our
GOPATHis/home/tan/go, a package with source$GOPATH/src/foo/barcan be imported as"foo/bar"and has its compiled form installed to "GOPATH/pkg/GOOS_GOARCH/foo/bar.a"
-bin:
-
Holds compiled commands.
-
Each command is named by its source directory(final element, not the entire path).
- So
$GOPATH/src/foo/quuxis installed into$GOPATH/bin/quuxnot$GOPATH/bin/foo/quux
- So
-
GOBIN-$ go env GOBINIf theGOBINenvironment variable is set, commands are installed to the directory it names instead ofGOPATH/bin.-
GOBINmust be an absolute path.
-
GOPATH=/home/tan/go
/home/tan/go/
src/
foo/
bar/ (go code in package bar)
x.go
quux/ (go code in package main)
y.go
bin/
quux (installed command)
pkg/
linux_amd64/
foo/
bar.a (installed package object)___________________________________________________________--- References: