see:
MacOSX
$ brew install go
$ go version
# for local go repository
$ mkdir ~/go
open .bashrc
#go lang
export GOROOT=`go env GOROOT`
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
$ mkdir -p $GOPATH/src/github.com/rkaneko/hello
- $GOPATH/github.com/rkaneko/hello/hello.go
package main
import "fmt"
func main() {
fmt.Printg("Hello, world.\n")
}
$ cd $GOPATH/src
$ go run github.com/rkaneko/hello/hello.go
Hello, world.
$ cd $GOPATH/src
$ go build github.com/rkaneko/hello
# If you want add hello binary to $GOPATH/bin, type under.
$ go install github.com/rkaneko/hello
$ tree $GOPATH
├── bin
│ └── hello
├── pkg
│ └── darwin_amd64
│ └── github.com
│ └── rkaneko
└── src
└── github.com
└── rkaneko
├── hello
└── hello.go
$ hello
Hello, world.
- $GOPATH/src/github.com/rkaneko/newmath/newmath_test.go
package newmath
import "testing"
func TestSqrt(t *testing.T) {
const in, out = 4, 2
if x := Sqrt(in); x != out {
t.Error("Sqrt(%v) = %v, want %v", in, x, out)
}
}
$ go test github.com/rkaneko/newmath
ok github.com/rkaneko/newmath 0.021s
# see more information for testing
$ go help test
- nsf/gocode
- golint
TODO
vim-goがあればいらないかも
- (13) Short variable declarations
- (15) Type conversions (more simply)
- Unlike in C, Go doesn't convert type implicitly.
- (30) The new funcion
- (36) Range
- Iterate over a slice or map
- (42) How to see if map's key or value exists or not
- (49) Switch with no condition
- convenient when u writes long if then else chains
- (52) Methods
- put receiver between func keyword and method name
- (54) Methods with pointer receivers
- (57) Errors
- (63) strings.NewReader("some string"), io.Copy(os.Stdout, pointer of []byte)