mfks17's blog(Life is Good !!)

趣味や思った事を書いていくと思います

Google App Engine for Goの環境構築

GAE for Golangのセットアップのメモ。

環境

  • macbookpro Early 2011
  • OS Lion

Google App Engine SDK for Goのダウンロード


ここからダウンロード

ダウンロードしてきたファイルを解凍し、任意の場所は配置します。

私の環境だと、こんな感じです。

次に環境変数PATHの登録をします。

export PATH=/path/to/google_appengine_go:$PATH

Hello Worldする


※手順

  • 配置したgoogle_appengine_goディレクトリにappディレクトリを作成
  • 作成したディレクトリ内にhelloworldディレクトリを作成
  • app.yamlを作成
  • helloディレクトリを作成
  • helloディレクトリ内にhello.goを作成
  • ローカルサーバを起動してブラウザで結果を確認

まずは、サンプルの作成
ディレクトリ構造はこんな感じ

.
└── helloworld
   ├── app.yaml
   └── hello
     └── hello.go

app.yaml

application: helloworld
version: 1
runtime: go
api_version: go1

handlers:
- url: /.*
    script: _go_app

hello.go

package hello
import (
    "fmt"
    "http"
)
func init() {
    http.HandleFunc("/", handler)

}
func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "Hello World!!")
}

次に、サーバを立ちあげます。

$ dev_appserver.py --port=8082 ../../helloworld/
WARNING  2013-01-25 19:11:41,772 rdbms_mysqldb.py:74] The rdbms API is not available because the MySQLdb library could not be loaded.
Allow dev_appserver to check for updates on startup? (Y/n): yes
dev_appserver will check for updates on startup.  To change this setting, edit /Users/typosterr/.appcfg_nag
INFO     2013-01-25 19:11:46,320 appcfg.py:586] Checking for updates to the SDK.
INFO     2013-01-25 19:11:46,951 appcfg.py:620] This SDK release is newer than the advertised release.
WARNING  2013-01-25 19:11:46,951 dev_appserver.py:3571] The datastore file stub is deprecated, and
will stop being the default in a future release.
Append the --use_sqlite flag to use the new SQLite stub.

You can port your existing data using the --port_sqlite_data flag or
purge your previous test data with --clear_datastore.

WARNING  2013-01-25 19:11:46,952 datastore_file_stub.py:518] Could not read datastore data from /var/folders/2v/65xkhxqx7rv90n_t2d802dx80000gn/T/dev_appserver.datastore
WARNING  2013-01-25 19:11:46,952 simple_search_stub.py:954] Could not read search indexes from /var/folders/2v/65xkhxqx7rv90n_t2d802dx80000gn/T/dev_appserver.searchindexes
WARNING  2013-01-25 19:11:46,958 dev_appserver.py:3670] Could not initialize images API; you are likely missing the Python "PIL" module. ImportError: No module named _imaging
INFO     2013-01-25 19:11:46,962 dev_appserver_multiprocess.py:655] Running application dev~helloworld on port 8082: http://localhost:8082
INFO     2013-01-25 19:11:46,962 dev_appserver_multiprocess.py:657] Admin console is available at: http://localhost:8082/_ah/admin

ここでhttp://localhost:8082/_ah/adminにアクセスします

できたっぽい

まとめ


今回は、GAE for Goの環境を構築しました。
素晴らしい先人達のおかげで、すんなりいきました。
Goの開発は活発ですね。

参考サイト


  • Go言語プログラミング入門on Google App Engine

    Go言語プログラミング入門on Google App Engine

    Go言語プログラミング入門on Google App Engine