shiny toy #1: the go command

Skip to first unread message

Russ Cox

Dec 22, 2011, 11:21:08 PM12/22/11
to golang-dev
As the weekly notes say, there is a new command named 'go'
for building and testing go programs; it will replace
gomake/gotest/goinstall before Go 1.

The go command has rough edges and is not yet complete;
these notes explain how to take it out for a test drive
anyway, if you are feeling adventurous.

To try the go command, your source code needs to be in a
directory tree mentioned by $GOPATH, like you currently do
for goinstall. The main requirement is that the code be in
a directory named src/import/path, where import/path
typically begins with a host name like or Run 'go help gopath' for details. An example
to get you started:

export GOPATH=/tmp/hack
hg clone \
ls /tmp/hack/src/

The go command will replace goinstall but it does not yet
implement that functionality; for now you still need to use
explicit version control commands (as above) or goinstall
(without a space) to download code.

Some recipes to try:

go list all
go list -f '{{.ImportPath}} {{.Deps}}' std
go list -f '{{.Dir}}' strconv
go list -json

cd $GOPATH/src/
go build
go install
go test
go test fmt .

cd $HOME
go test fmt

go install
go vet

cd $HOME
cat >x.go <<EOF
package main

import "fmt"

func main() {
fmt.Printf("hello, world\n")
go run x.go

If you have questions or run into problems, please reply to this mail.
If you have complaints or suggestions for changes, please enter
them as comments at



Jan 4, 2012, 1:49:55 AM1/4/12
I am amazed at how simple it was to cross compile a program for windows!!
`GOOS=windows go build` was all I had to do. Of course now I have to fix all the newline related bugs in my code, but still...



Fun fact: unicode has 8 valid representations for a newline 4 of which are single 1 byte runes, 1 is a 2 byte rune, 2 are 3 byte runes, and 1 is composed of 2 1 byte runes (ie CR+LF) that both independently are also valid representations for a newline. (All of this is referring to UTF-8 of course) 

Reply all
Reply to author
0 new messages