shiny toy #1: the go command

250 views
Skip to first unread message

Russ Cox

unread,
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 code.google.com or
github.com. Run 'go help gopath' for details. An example
to get you started:

export GOPATH=/tmp/hack
hg clone https://code.google.com/p/go.example \
$GOPATH/src/code.google.com/p/go.example
ls /tmp/hack/src/code.google.com/p/go.example/newmath

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 code.google.com/p/go.example/newmath

cd $GOPATH/src/code.google.com/p/go.example/newmath
go build
go install
go test
go test fmt .

cd $HOME
go test fmt code.google.com/p/go.example/newmath

go install code.google.com/p/go.example/hello
$GOPATH/bin/hello
go vet code.google.com/p/go.example/hello

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

import "fmt"

func main() {
fmt.Printf("hello, world\n")
}
EOF
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 http://golang.org/issue/2606.

Thanks.
Russ

sanjay.m

unread,
Jan 4, 2012, 1:49:55 AM1/4/12
to golan...@googlegroups.com, r...@golang.org
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...

Kudos,

Sanjay


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
Forward
0 new messages