LoginSignup
2
1

More than 5 years have passed since last update.

Google App Engine で始める Go 実践入門 Part 5 【Visual Studio Code】

Last updated at Posted at 2019-03-31

連載を通して簡単なブログアプリを作成しつつ Go/GAE について学んでいきます。
今回は Visual Studio Code についての説明です。

Visual Studio Code で Go の開発準備

Visual Studio Code (以下 VS Code) に Go の拡張機能を導入することによってコーディングの生産性を上げることができます。

Go の拡張機能は次の手順で導入ができます。

[VS Code を起動] > [Command + P] > [ext install ms-vscode.go] > [Enter]

次に Linter や Debugger などのツールを導入していきます。
通常は go get コマンドでインストールするのですが、Go 拡張機能を使うと簡単にツール一式をインストールすることが可能です。

[VS Code を起動] > [F1] > [>Go: Install/Update Tools] > [チェックボックス全てにチェック] > [OK]

インストールが完了すると、これらツールが GOPATH 配下にインストールされたことが分かります。
PATH に $GOPATH/bin を追加しているので、これらコマンドはターミナルから呼び出すことができます。

$GOPATH
  ├── bin
  │     ├── impl
  │     ├── guru
  │     ├── gotests
  │     ├── goreturns
  │     ├── gorename
  │     ├── goplay
  │     ├── gopkgs
  │     ├── gomodifytags
  │     ├── golint
  │     ├── godef
  │     ├── gocode-gomod
  │     ├── gocode
  │     ├── go-symbols
  │     ├── go-outline
  │     ├── fillstruct
  │     └── dlv
  ├── pkg
  │     └── darwin_amd64
  └── src
        ├── github.com
        │     ├── uudashr
        │     ├── stamblerre
        │     ├── sqs
        │     ├── skratchdot
        │     ├── rogpeppe
        │     ├── rema424
        │     ├── ramya-rao-a
        │     ├── pkg
        │     ├── mdempsky
        │     ├── karrick
        │     ├── josharian
        │     ├── haya14busa
        │     ├── golang
        │     ├── go-delve
        │     ├── fatih
        │     ├── davidrjenni
        │     ├── cweill
        │     └── acroca
        └── golang.org
              └── x

最後に VS Code の設定ファイルを作り、拡張機能をカスタマイズします。
Go 拡張機能では Format ツールがデフォルトでは goreturns となっていますが、今後導入するパッケージ管理ツール dep との相性を考えて gofmt に変更します。

まずは設定ファイルをプロジェクトディレクトリの中に作ります。

# ディレクトリ移動
cd $GOPATH/src/rema424/go-gae-blog-app-example

# ディレクトリ作成
mkdir .vscode

# 設定ファイル作成
touch .vscode/settings.json

ファイルが作成できたら、次の内容を書き込んで完了です。

.vscode/settings.json
{
    "go.formatTool": "gofmt",
    "editor.formatOnSave": true
}

おわりに

次回のテーマは『Hello World』です。

よかったら Twitter フォローしてね。@_rema424

2
1
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
2
1