LoginSignup
28
32

More than 5 years have passed since last update.

Windows 使いの為の GAE/Go 開発環境構築

Last updated at Posted at 2016-08-11

Google Cloud Platform の PaaS, Google App Engine のサービスをGo言語で開発したいWindows使いの為の備忘録。64bitのWindows10環境で確認済みですが、たぶんWindows7以降なら大丈夫です。

メニュー

Google Chrome インストール

EdgeやIE11でも作業可能ですが、特別な理由がない限りは入れときましょう。
https://www.google.co.jp/chrome/browser/desktop/index.html

Google Account 準備

Google Cloud Console を使うには Google Account が必須となります。 G Suite アカウントか、フリーの Gmail アカウントを準備してください。
※G Suite の場合、管理者側でGCPプロジェクトの作成を禁止しているケースがありますので、管理者に問い合わせてください。

Google Cloud Platform プロジェクト準備

https://console.cloud.google.com/ にアクセスするとGoogle Accountでのログインが求められます。
ログインし、左上のプロジェクトメニューから新規プロジェクトを選択、新しいプロジェクトを作成してください。
image
好きな名前を付けて作成。プロジェクト名とプロジェクトIDはメモっておいてください。
image

Google Cloud SDK

インストールすると、今後多用するgcloud コマンドが使えるようになります。
Google Cloud SDKのインストールについては https://cloud.google.com/sdk/ に詳細な解説がありますが、以下に要約を記載します。

Google Cloud SDK for Windows をダウンロードして実行、インストールしてください。途中画面のチェックボックスは基本すべてチェックします。
インストールが完了すると、gcloud コマンドプロンプトが立ち上がりますので、[1]を選択してください。初回設定時にはGoogle Accountへのログイン画面が表示されますので、開発用に用意したGoogle Accountでログインします。

gloud.console
Pick configuration to the:
 [1] Re-initialize this configuration [default] with new settings
 [2] Create a new configuration
Please enter your numeric choice:  1

さらに[1]を選んで現在ログイン中のアカウントについての設定を選択。

Choose the account you would like use to perform operations for this
configuration:
 [1] youraccount@google.com
 [2] Log in with a new account
Please enter your numeric choice:

gcloudコマンドを叩いた際、プロジェクトの指定がない場合のデフォルトプロジェクトを選択します。

You are logged in as: [youraccount@google.com].

Pick cloud project to use:
 [1] [sugoiproject1-1234]
 [2] [sugoiproject2-1234]
Please enter your numeric choice:

続いて Compute Engine のデフォルトゾーンが聞かれるので、東京リージョンを選択適当なリージョンを選択してください。

Do you want to configure Google Compute Engine
(https://cloud.google.com/compute) settings (Y/n)?  y

Which Google Compute Engine zone would you like to use as project
default?
If you do not specify a zone via a command line flag while working
with Compute Engine resources, the default is assumed.
 [1] [asia-east1-c]
 [2] [asia-east1-b]
 [3] [asia-east1-a]
 [4] [europe-west1-c]
 [5] [europe-west1-d]
 [6] [europe-west1-b]
 [7] [us-central1-c]
 [8] [us-central1-f]
 [9] [us-central1-a]
 [10] [us-central1-b]
 [11] [us-east1-c]
 [12] [us-east1-d]
 [13] [us-east1-b]
 [14] [us-west1-b]
 [15] [us-west1-a]
 [16] Do not set default zone
Please enter your numeric choice:

App Engine Go Extensions のインストール

PowerShell か コマンドラインプロンプトを管理者モードで開きます。
gcloud components list コマンドでインストール可能なコンポーネント一覧が表示されます。

PS PS C:\WINDOWS\system32> gcloud components list

Your current Cloud SDK version is: 152.0.0
The latest available version is: 152.0.0

+-------------------------------------------------------------------------------------------------------------+
|                                                  Components                                                 |
+---------------+------------------------------------------------------+--------------------------+-----------+
|     Status    |                         Name                         |            ID            |    Size   |
+---------------+------------------------------------------------------+--------------------------+-----------+
| Not Installed | App Engine Go Extensions                             | app-engine-go            |  48.4 MiB |
| Not Installed | Bigtable Command Line Tool                           | cbt                      |   3.9 MiB |
| Not Installed | Cloud Datalab Command Line Tool                      | datalab                  |   < 1 MiB |
| Not Installed | Cloud Datastore Emulator                             | cloud-datastore-emulator |  15.4 MiB |
| Not Installed | Cloud Datastore Emulator (Legacy)                    | gcd-emulator             |  38.1 MiB |
| Not Installed | Cloud Pub/Sub Emulator                               | pubsub-emulator          |  21.0 MiB |
| Not Installed | Emulator Reverse Proxy                               | emulator-reverse-proxy   |  14.5 MiB |
| Not Installed | Google Container Registry's Docker credential helper | docker-credential-gcr    |   3.3 MiB |
| Not Installed | gcloud Alpha Commands                                | alpha                    |   < 1 MiB |
| Not Installed | gcloud app Java Extensions                           | app-engine-java          | 128.6 MiB |
| Not Installed | gcloud app PHP Extensions (Windows)                  | app-engine-php-windows   |  19.1 MiB |
| Not Installed | gcloud app Python Extensions                         | app-engine-python        |   6.1 MiB |
| Installed     | BigQuery Command Line Tool                           | bq                       |   < 1 MiB |
| Installed     | Cloud SDK Core Libraries                             | core                     |   5.9 MiB |
| Installed     | Cloud Storage Command Line Tool                      | gsutil                   |   2.9 MiB |
| Installed     | Default set of gcloud commands                       | gcloud                   |           |
| Installed     | gcloud Beta Commands                                 | beta                     |   < 1 MiB |
| Installed     | kubectl                                              | kubectl                  |  14.9 MiB |
+---------------+------------------------------------------------------+--------------------------+-----------+
To install or remove components at your current SDK version [152.0.0], run:
  $ gcloud components install COMPONENT_ID
  $ gcloud components remove COMPONENT_ID

To update your SDK installation to the latest version [152.0.0], run:
  $ gcloud components update

gcloud components install app-engine-go でApp Engine Go Extensions をインストールしてください。

Git for Windows インストール

https://git-for-windows.github.io/ の「Download」からパッケージをダウンロードして実行、インストールを進めてください。
基本デフォルトのまま進めて構いませんが、次の画面では一番下の選択肢をおすすめします。Windows 標準のfindやsortなんて誰も使ってないでしょ?
image
次の改行コードの変換については、
Checkout as-is, commit as-isを強くおすすめします。WindowsのnotepadはLFのみでは改行表示してくれないのですが、本稿でインストールするVisual Studio Codeも一般的なテキストエディタもLFでちゃんと改行表示してくれます。改行コード変換による弊害は、気づきにくいトラブルを生み、百害あって一利なしです。
Configuring the terminal emulator to use With Git Bash は、個人的にはUse Windows’ default console windowがいいです。Windowsのコマンドプロンプトも結構使い勝手良くなってます。
次のキャッシュに関するオプションは両方ともチェックを入れておくとわりと幸せです。

Node.js

npm を使うためにもNode.jsをインストールします。
https://nodejs.org/en/download/ からWindows Installer をクリックし、実行します。

Golang SDK インストール

Golang SDK から最新のmsiを選んでダウンロード、実行してください。インストールパスはデフォルトのままC:\Go\とします。インストーラーはSDKをインストールし、システム環境変数のパスにC:\go\binを追加します。PowerShellを起動し、goとタイプしてパスが通っている事を確認してください。

環境変数 GOPATH の設定

Powershell プロンプトからsetx GOPATH $HOME\.goとタイプ。Get-ChildItem env:gopath で環境変数が追加されていることを確認します。
環境変数を有効化するために一旦PowerShell Windowを閉じます。

$home は PowerShellの自動変数ですので、上記コマンドを普通のコマンドプロント(cmd)で実行するとGOPATH=$HOME\.go とそのまま入ってしまうので注意。

Visual Studio Code インストール

https://code.visualstudio.com/download からOSを選択して(Windowsですよね)ダウンロード、実行します。追加オプションは全部ONで。インストールが終わると Visual Studio Code が起動して https://code.visualstudio.com/docs?start=true が表示されます。

Golang 開発の為のセットアップ

引き続きGolangで開発するための初期設定を行います。Visual Studio code 左側メニューから、拡張機能ボタンをクリックし、候補からGoを選択してインストールをクリックします。
image

次にPowerShell プロンプトを開き、環境変数GOPATHで設定したフォルダを作成、移動し、Visual Studio Code を起動します。

PS C:\Users\you>mkdir .go


    ディレクトリ: C:\Users\you


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2016/08/11     15:22                .go

PS C:\Users\you> cd .go
PS C:\Users\you\.go>code

右下の「プレーンテキスト」をクリックし、言語モードの選択リストからGoを選びます。
image
右下が「Analysis Tools Missing」に変わるのでクリックします。
エディタ上部で「Some Go analysys tools are missing from your GOPATH. Would you like to install them?」聞かれるので、素直にInstallをクリックします。

Installing 9 missing tools
  gocode
  goreturns
  gopkgs
  godef
  golint
  go-outline
  go-symbols
  guru
  gorename

Installing gocode SUCCEEDED
Installing goreturns SUCCEEDED
Installing gopkgs SUCCEEDED
Installing godef SUCCEEDED
Installing golint SUCCEEDED
Installing go-outline SUCCEEDED
Installing go-symbols SUCCEEDED
Installing guru SUCCEEDED
Installing gorename SUCCEEDED

All tools successfully installed. You're ready to Go :).

You're ready to Go :)

28
32
3

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
28
32