Skip to content

Instantly share code, notes, and snippets.

@gianpaolof
Forked from sathiyaseelan/golang_setup.md
Last active February 27, 2023 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gianpaolof/b7d6321415e2af1faaf54648ebc0576d to your computer and use it in GitHub Desktop.
Save gianpaolof/b7d6321415e2af1faaf54648ebc0576d to your computer and use it in GitHub Desktop.
Basics to setup a golang project repo in your local

Simple Guide to setup Golang in your Mac and clone a repo.

Setup Go and workspace

Type go in terminal, to verify the installation.

  • Create a Go workspace and set GO PATH
mkdir -p $HOME/go
export GOPATH="$HOME/go"

# Folder contains your golang source codes
mkdir -p $GOPATH/src

# Folder contains the binaries when you install an go based executable
mkdir -p $GOPATH/bin

# Folder contains the Go packages you install
mkdir -p $GOPATH/pkg

# Folder contains the Github Source code for the repos you cloned
mkdir -p $GOPATH/src/github.com

All your imports will be resolved from this GO PATH only

For more info: https://golang.org/cmd/go/#hdr-GOPATH_environment_variable

Cloning a go project repo.

The folder structure to maintain the local repo is $GOPATH/src/github.com//

For this document, let's assume you're cloning the below repo. https://github.com/keratin/authn-server

mkdir -p $GOPATH/src/github.com/keratin/authn-server
#cd $GOPATH/src/github.com/keratin/authn-server

I would go here:
cd $GOPATH/src/github.com/keratin


git clone git@github.com:keratin/authn-server.git

Installing Go packages

To install a go package, you can use go get command.

go get github.com/benbjohnson/ego/cmd/ego

go get github.com/airbrake/gobrake

Note: Depends on the package, it may install a binary under $GOPATH/bin or a package in $GOPATH/pkg

Using Glide

Glide is a package manager for go-lang. Some projects use Glide for maintaining the Go packages. This is similar bundler in rails or maven in Java.

To install Glide

brew install glide

To install the pacakges in glide.yaml

glide install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment