Go cli

From bibbleWiki
Revision as of 02:41, 30 January 2021 by Iwiseman (talk | contribs) (Build)
Jump to navigation Jump to search

Introduction

This is just a page on go command options

go help <command>
// e.g.
go help test

We can go to https://golang.org/cmd/go/ for online

Building and Running

Environment

For me I have set up my PATH to include go and my GOROOT to be the parent directory of the src folder.

export PATH=/usr/local/go/bin:$PATH
cd blah1/blah2/src/..
export GOPATH=`pwd`

Run

Compiles and run a program without leaving artefacts.

go run src/cmds/hello/hello.go

Build

Compiles but does not run a program. Given the tree

This command will build the library but not produce anything.

go build hello

This command will build the binary and produce a binary

go build cmds/hello

Adding the -i forces the intermediate files to be created on disk in the pkg directory

go build -i cmds/hello