107
101

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Macでgo言語開発環境を作る

Last updated at Posted at 2014-07-02

##インストール
brewで入れます。

$ brew install go
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/go-1.2.2.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring go-1.2.2.mavericks.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
?  /usr/local/Cellar/go/1.2.2: 3981 files, 115M

はいった。確認。

$ go version
go version go1.2.2 darwin/amd64
$
$
$
$go help
Go is a tool for managing Go source code.

Usage:

	go command [arguments]

The commands are:

    build       compile packages and dependencies
    clean       remove object files
    env         print Go environment information
    fix         run go tool fix on packages
    fmt         run gofmt on package sources
    get         download and install packages and dependencies
    install     compile and install packages and dependencies
    list        list packages
    run         compile and run Go program
    test        test packages
    tool        run specified go tool
    version     print Go version
    vet         run go tool vet on packages

Use "go help [command]" for more information about a command.

Additional help topics:

    c           calling between Go and C
    gopath      GOPATH environment variable
    importpath  import path syntax
    packages    description of package lists
    testflag    description of testing flags
    testfunc    description of testing functions

Use "go help [topic]" for more information about that topic.

はいってるぽい。

##HelloWorldしてみる。

まず、Hello.goファイルを作成して、以下のように書く。

go,hello.go
  1 package main
  2
  3 import "fmt"
  4
  5
  6 func main() {
  7     SayHello()
  8 }
  9
 10 func SayHello() {
 11     fmt.Println("Hello World for go lang")
 12 }

ビルドする。

go build hello.go

すると、helloという実行ファイルができる。
ということで、実行してみる。

$ ./hello
Hello World for go lang

やっぽい。

##パスの設定

go getなどで、goのモジュールをどんどんインストールできるようなんだけど、
$GOPATHが設定されていないとおこられるよう。
どこでもいいので、今は、以下のように.zshrcに設定した。

18 if [ -x "`which go`" ]; then
19       export GOROOT=`go env GOROOT`
20       export GOPATH=$HOME/code/go-local
21       export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
22 fi

##最後に

net/httpモジュールがかなり便利らしく、簡単にwebサーバを立てられるみたい。
高速が売りなので、バックエンド側のPHPソースを入れ替えたい。

あと、revelなどのweb frameworkなどが使いやすいのか使ってみる予定。

以上。

107
101
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
107
101

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?