Skip to content

Instantly share code, notes, and snippets.

@kyokomi
Created July 27, 2014 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyokomi/44c4cca8561ffbdf3700 to your computer and use it in GitHub Desktop.
Save kyokomi/44c4cca8561ffbdf3700 to your computer and use it in GitHub Desktop.
golangのweb framework martiniをgaeに動かすときのメモ

ローカルのGAE環境

SDKインストール

$ brew install go-app-engine-64

ローカルでデバッグ起動

$ dev_appserver.py --admin_port=9998 --port=9999 ./
  • 管理画面が9998ポートで入れる
  • アプリが9999ポートで入れる

GAEで実装する際の注意

GAEのSDKにmain()が入っているので、デプロイするアプリにはmain抜きで実装する。 また、http.ListenAndServeは中でやってくれてるので、不要。

Martiniを使う場合

m.Run()で起動しないで以下のように修正する必要がある。 (2重にhttp.ListenAndServeを呼ぶことになってしまうため)

package server

import (
	"github.com/go-martini/martini"
	"net/http"
)

func init() {
  m := martini.Classic()

  // ...省略...

  // m.Run()
  http.Handle("/", m)
}

GAEへのデプロイ

ローカルからデプロイする場合

$ appcfg.py --oauth2 --noauth_local_webserver  update ./

実行するとoauth認証のURLがコンソール上に吐かれて、 アクセストークンの入力待ちになる。

ブラウザでoauth認証してリダイレクト先のURLにあるトークンをコピして、 コンソールに貼り付けて実行。

おわり。

Werckerからデプロイする場合

Two-factor-authのgoogleアカウントだとmailとpassのデプロイできなくて、 oauth2認証が必要なので無理っぽい。

stepのgithubはこちら

https://github.com/pjvds/step-go-appengine-deploy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment