GO Lang を弄ってみる こんにちはせかい (1)

GoCON 行くので、少しでも、弄っておく。

インストールから、こんにちは世界まで。。

Go言語のインストール - golang.jp

MBA20120331:golang guutara$ brew install go
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/go-1.2.2.lion.bottle.tar.gz
######################################################################## 100.0%
==> Pouring go-1.2.2.lion.bottle.tar.gz
==> Caveats
As of go 1.2, a valid GOPATH is required to use the `go get` command:
  http://golang.org/doc/code.html#GOPATH

`go vet` and `go doc` are now part of the go.tools sub repo:
  http://golang.org/doc/go1.2#go_tools_godoc

To get `go vet` and `go doc` run:
  go get code.google.com/p/go.tools/cmd/godoc
  go get code.google.com/p/go.tools/cmd/vet

You may wish to add the GOROOT-based install location to your PATH:
  export PATH=$PATH:/usr/local/opt/go/libexec/bin

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completion has been installed to:
  /usr/local/share/zsh/site-functions
==> Summary
sh: find: command not found
🍺  /usr/local/Cellar/go/1.2.2: 115M
MBA20120331:golang guutara$ go run hellow.go 
hello, world


go install で、パッケージでやってみる。
パッケージにする為に、goの作業用ディレクトリにsrc/helloを作り、ソースを配置した。
$GOPATH なしだと、エラーになった。
$GOPATH 設定して、無事作成完了。
$GOROOT は、なしでいけた。

MBA20120331:bin guutara$ mkdir -p ~/golang/src/hello
MBA20120331:bin guutara$ ls ~/golang/src/hello/
hellow.go
MBA20120331:bin guutara$ echo $GOPATH

MBA20120331:bin guutara$ go install hello
can't load package: package hello: cannot find package "hello" in any of:
	/usr/local/Cellar/go/1.2.2/libexec/src/pkg/hello (from $GOROOT)
	($GOPATH not set)
MBA20120331:bin guutara$ export GOPATH=/Users/guutara/golang
MBA20120331:bin guutara$ echo $GOPATH
/Users/guutara/golang
MBA20120331:bin guutara$ go install hello
MBA20120331:bin guutara$ ls $GOPATH/bin
hello
MBA20120331:bin guutara$ /Users/guutara/golang/bin/hello 
hello, こんにちは世界