Go cli: Difference between revisions
Jump to navigation
Jump to search
Line 8: | Line 8: | ||
We can go to https://golang.org/cmd/go/ for online | We can go to https://golang.org/cmd/go/ for online | ||
=Building and Running= | =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. | |||
<syntaxhighlight lang="bash"> | |||
export PATH=/usr/local/go/bin:$PATH | |||
cd blah1/blah2/src/.. | |||
export GOPATH=`pwd` | |||
</syntaxhighlight> | |||
==Run== | ==Run== | ||
Compiles and run a program without leaving artefacts. | Compiles and run a program without leaving artefacts. | ||
Line 17: | Line 24: | ||
<br> | <br> | ||
[[File:Go cli tree.png]] | [[File:Go cli tree.png]] | ||
<br> | |||
This command will build the library but not produce anything. | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
go build hello | go build hello | ||
</syntaxhighlight> | </syntaxhighlight> | ||
This command will build the binary and produce a binary | |||
<syntaxhighlight lang="bash"> | |||
go build cmds/hello | |||
</syntaxhighlight> | |||
Adding the -i forces the intermediate files to be created on disk in the pkg directory | |||
<syntaxhighlight lang="bash"> | |||
go build -i cmds/hello | |||
</syntaxhighlight> | |||
[[File:Go CLi Tree2.png]] |
Revision as of 02:41, 30 January 2021
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