12
11

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 と WebStorm で始める Go

Last updated at Posted at 2014-09-02

[2014/09/03追記]

  • こういう GOPATH の管理の方が良いのかしら?

まだコンニチワまでしか進んでないので、ほぼ自分用のメモです。
WebStorm を利用しているのは、単純に、馴染んでいる IDE がこれだから、です..

環境構築(Mac)

自分の環境:
OS:Mac OS X 10.9.4 (Mavericks)
HomeBrew:0.9.5
Go:結果、1.3 になりました

  • といっても、インストールは brew コマンドで一発。

     $ brew install go
    
  • バージョンの表示

     $ go version
     
     go version go1.3 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
         filetype    file types
         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.
    
  • WebStorm を適当なプロジェクトで起動し、Go 用の Plugin を追加

    スクリーンショット 2014-09-02 12.13.35.png

  • 環境変数 GOROOT GOPATH を追加

    .bash_profile
     export GOROOT=/usr/local/opt/go/libexec
     export GOPATH=$HOME/.go
    

    GOPATH は外部ライブラリのインストール先で、どこでもいいらしい

  • このままだと WebStorm からは環境変数を認識してくれないので、

    /etc/launchd.conf(新規に作成)
     setenv GOROOT /usr/local/opt/go/libexec
     setenv GOPATH $HOME/.go
    
  • OSを再起動する(もしかして他に方法があるかもしれない..)。

WebStorm でプロジェクトを作成

  • 新規プロジェクトの作成(Create New..)で、Type に Go Application を選択。

    スクリーンショット 2014-09-02 23.17.22.png

  • そのまま [OK] を選択。

    スクリーンショット 2014-09-02 23.17.43.png

  • 基本構成の状態で、ファイルが作成されている。

    スクリーンショット 2014-09-02 23.37.05.png

    pkg ディレクトリがあるのは、昔のなごり??

  • ビルドして実行ファイルを作ってみる。

    • この際、環境変数 GOBIN が設定されていないとエラーになるので、下記のように指定。

    • $ go env とすると、各種の環境変数の値が確認できます。

       $ cd go-hello
       $ export GOBIN=`pwd`/bin
       $ go install src/go-hello.go 
      
    • 実行ファイルが bin/go-hello に作成される。

      • コマンドラインから $ bin/go-hello で実行できる。

      スクリーンショット 2014-09-02 23.39.43.png

終わりに

Google社が開発している Go なので、GAEと相性がいいのだろうか。とりあえず WebStorm から GAE に簡単にデプロイできそうなメニューを発見。(GAEのアカウント持ってないので、続きはまた今後..)

スクリーンショット 2014-09-02 18.15.05.png

12
11
0

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
12
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?