Go Basics: Difference between revisions
Jump to navigation
Jump to search
Line 36: | Line 36: | ||
== Commands == | == Commands == | ||
<pre> | <pre> | ||
godoc | godoc -http=:8000 # host docs at http://localhost:8000 | ||
go build # create binary file in local directory | go build # create binary file in local directory | ||
go install # create binary file | go install # create binary file in $GOPATH/bin | ||
go run # just run it, disposing of binary | go run # just run it, disposing of binary | ||
go get github.com/nsf/gocode # grab a remote package and install it to $GOPATH/bin | go get github.com/nsf/gocode # grab a remote package and install it to $GOPATH/bin | ||
go get -u github.com/nsf/gocode # update to latest version of remote package | go get -u github.com/nsf/gocode # update to latest version of remote package | ||
</pre> | </pre> |
Revision as of 19:46, 7 February 2014
Resources: http://golang.org/
Install and Setup
sudo apt-get install golang
http://golang.org/doc/code.html discusses setting up the GOLANG environment variable and your code repository
mkdir -p $HOME/projects/go/src export GOPATH=$HOME/projects/go (add this to .profile too)
Hello World
// hello.go package main import ( "fmt" "os" "strings" ) func main() { who := "World!" if len(os.Args) > 1 { /* os.Args[0] is "hello" or "hello.exe" */ who = strings.Join(os.Args[1:], " ") } fmt.Println("Hello", who) }
Commands
godoc -http=:8000 # host docs at http://localhost:8000 go build # create binary file in local directory go install # create binary file in $GOPATH/bin go run # just run it, disposing of binary go get github.com/nsf/gocode # grab a remote package and install it to $GOPATH/bin go get -u github.com/nsf/gocode # update to latest version of remote package