gcp ja night #27 Google Cloud Endpoints with Golang

Post on 25-Jun-2015

1.151 views 3 download

Tags:

description

gcp ja night #27 Google Cloud Endpoints with Golang

Transcript of gcp ja night #27 Google Cloud Endpoints with Golang

Google Cloud Endpointswith Golang

誰?

大橋啓介

と申します

@soundTricker318http://goo.gl/ZpUOs

どこの

人?

http://www.bfts.co.jp

何やってる?

https://www.flickr.com/photos/centralasian/ (CC)

電車プログラマ

話す事http://creativecommons.org/licenses/by/3.0/ushttps://github.com/mholt/golang-graphics/blob/master/official/talks.png

Google Cloud Endpointswith

Golang

Google CloudEndpoints?

https://developers.google.com/appengine/docs/java/endpoints/

What?Google CloudEndpoints?

https://developers.google.com/appengine/docs/java/endpoints/

What?Google CloudEndpoints?

AppEngine 上に

バックエンド API を

簡単に作成する仕組

https://developers.google.com/appengine/docs/java/endpoints/

What?Google CloudEndpoints?

作成した API に対するクライアントライブラリを

自動生成

使える言語Google CloudEndpoints?

サーバサイド

使える言語Google CloudEndpoints?

サーバサイド

PythonPython でCloud Endpoints の事例をあまりみないのでどっか LT とかするとウケそう

使える言語Google CloudEndpoints?

サーバサイド

Java事例もよく見るので始めるのは楽かもJAX-RS に似てるでも結構違う

http://www.flickr.com/photos/andypiper/

使え… ..Google CloudEndpoints?

サーバサイド

PHP過去に Developer Live で簡単なバージョンが実装されるもその後詳細不明…

https://www.youtube.com/watch?v=yue4X8rcGJU

使える言語Google CloudEndpoints?

サーバサイド

GoGoogle が直接サポートしているわけではなく、サードパーティフレームワークを使う ( 後述 ) 個人的には好き

http://www.flickr.com/photos/andybons/

使える言語Google CloudEndpoints?

クライアント

クライアントGoogle CloudEndpoints?

自動生成ライブラリ

AndroidCloud Endpoints と触ったことが無い ( ー `д ー ´) キリッ

https://www.flickr.com/photos/etnyk/

クライアントGoogle CloudEndpoints?

自動生成ライブラリ

iPhone持ってない ( ー `д ー ´) キリッ

https://www.flickr.com/photos/reticulating/

クライアントGoogle CloudEndpoints?

自動生成ライブラリ

JavaScript自動生成できる、Google API client for JavaScript 経由で利用時に作成されたものが使える感じ?

NoImage

クライアントGoogle CloudEndpoints?

自動生成ライブラリ

Dartサードパーティ製Dart を含めて自分で好きな言語のクライアント Library Gen は作れる

Google CloudEndpoints

TRY

サーバサイドGoogle CloudEndpoints

TRY

準備

サーバサイドGoogle CloudEndpoints

TRY

環境• Appengine Go SDK• Mac ユーザは brew からでも OK• 最近は Google Cloud SDK 推奨

$ curl https://dl.google.com/dl/cloudsdk/release/install_google_cloud_sdk.bash | bash

サーバサイドGoogle CloudEndpoints

TRY

ライブラリインストール• go-endpointsを使います• Cloud Endpoins フレームワーク

$ go get github.com/crhym3/go-endpoints/endpoints

※ インストール時にエラーが出ますが気にしないでください。

サーバサイドGoogle CloudEndpoints

TRY

ライブラリインストール (非必須 )• Datastore 周りは goon がオヌヌメ

• NDB みたいなもの

$ go get github.com/mjibson/goon

※ インストール時にエラーが出ますが気にしないでください。

サーバサイドGoogle CloudEndpoints

TRY

実装

サーバサイドGoogle CloudEndpoints

TRY

実装• 4 段階

1. 通信用構造体を作成2. サービス ( 実処理部 ) を作成3. サービスを登録4. app.yaml を登録

• 詳しくは↓ or →http://goo.gl/gBrZAD

サーバサイドGoogle CloudEndpoints

TRY

通信用構造体 (struct)を作成• go-endpoints が自動で

JSON←→Struct 変換してくれます。

サーバサイドGoogle CloudEndpoints

TRY

通信用構造体 (struct)を作成Datastore 格納兼 JSON 通信用

サーバサイドGoogle CloudEndpoints

TRY

通信用構造体 (struct)を作成JSON Array でやりとりする場合は別の構造体が必要

サーバサイドGoogle CloudEndpoints

TRY

通信用構造体 (struct)を作成QueryString 、 URL Param も Struct で表現注釈を付けれる

サーバサイドGoogle CloudEndpoints

TRY

サービス (実処理 )を作成• 単純なメソッドを定義します。• go-endpoints が変換した struct を

引数に渡してくれます。

サーバサイドGoogle CloudEndpoints

TRY

サービス (実処理 )を作成

サーバサイドGoogle CloudEndpoints

TRY

脇道 :goon• goon は Go 版 NDB みたいなもの• GAE/G の Datastore 周りを楽にして

くれる• Key 系の検索は全て in-memory,

Memcache にキャッシュ / 検索

サーバサイドGoogle CloudEndpoints

TRY

脇道 :goon

goon 無し

サーバサイドGoogle CloudEndpoints

TRY

脇道 :goon

goon 有り

サーバサイドGoogle CloudEndpoints

TRY

サービスを登録• サービスを go-endponts に登録

サーバサイドGoogle CloudEndpoints

TRY

サーバサイドGoogle CloudEndpoints

TRY

app.yamlで設定• go-endponts が動くようにします。

application: gpc-ja-night-27-go-endpointsversion: v1

runtime: goapi_version: go1

handlers:- url: /.* script: _go_app

# ここが絶対に必要- url: /_ah/spi/.* script: _go_app

サーバサイドGoogle CloudEndpoints

TRY

起動• appengine go SDK 経由

$ goapp serve

サーバサイドGoogle CloudEndpoints

TRY

テスト• http://localhost:8080/_ah/api/explor

er

とかに行けば試せる

サーバサイドGoogle CloudEndpoints

TRY

テスト

サーバサイドGoogle CloudEndpoints

TRY

リリース• goapp deploy でリリース

$ goapp deploy

Google CloudEndpoints

TRY

Demohttp://goo.gl/248Dh3

使い所 ?Google CloudEndpoints

TRY

メリット• 爆速スピンアップ• 処理に集中できる• テストしやすい気がする

End