Goを学ぶための gobyexample.comの和訳とメモです。
Install go
brew update
brew install go
Set Environment vairable in .bashrc or .zshrc
export GOROOT=/usr/local/opt/go/libexec
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
hello-world.go
package main
import "fmt"
func main() {
fmt.Println("hello world")
}
プログラムを実行するためには、上記のコードをhello-world.goに書き、go run
を使う。
バイナリにコンパイルしたいときは、go build
を使う。バイナリは直接実行できる。
$ go run hello-world.go
hello world
$ go build hello-world.go
$ ls
hello-world hello-world.go
$./hello-world
hello world