gcp ja night #27 Google Cloud Endpoints with Golang

51
Google Cloud Endpoints with Golang

description

gcp ja night #27 Google Cloud Endpoints with Golang

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

Page 1: gcp ja night #27 Google Cloud Endpoints with Golang

Google Cloud Endpointswith Golang

Page 2: gcp ja night #27 Google Cloud Endpoints with Golang

誰?

Page 3: gcp ja night #27 Google Cloud Endpoints with Golang

大橋啓介

と申します

Page 4: gcp ja night #27 Google Cloud Endpoints with Golang

@soundTricker318http://goo.gl/ZpUOs

Page 5: gcp ja night #27 Google Cloud Endpoints with Golang

どこの

人?

Page 6: gcp ja night #27 Google Cloud Endpoints with Golang

http://www.bfts.co.jp

Page 7: gcp ja night #27 Google Cloud Endpoints with Golang

何やってる?

Page 8: gcp ja night #27 Google Cloud Endpoints with Golang
Page 9: gcp ja night #27 Google Cloud Endpoints with Golang

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

電車プログラマ

Page 10: gcp ja night #27 Google Cloud Endpoints with Golang

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

Page 11: gcp ja night #27 Google Cloud Endpoints with Golang

Google Cloud Endpointswith

Golang

Page 12: gcp ja night #27 Google Cloud Endpoints with Golang

Google CloudEndpoints?

Page 13: gcp ja night #27 Google Cloud Endpoints with Golang

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

What?Google CloudEndpoints?

Page 14: gcp ja night #27 Google Cloud Endpoints with Golang

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

What?Google CloudEndpoints?

AppEngine 上に

バックエンド API を

簡単に作成する仕組

Page 15: gcp ja night #27 Google Cloud Endpoints with Golang

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

What?Google CloudEndpoints?

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

自動生成

Page 16: gcp ja night #27 Google Cloud Endpoints with Golang

使える言語Google CloudEndpoints?

サーバサイド

Page 17: gcp ja night #27 Google Cloud Endpoints with Golang

使える言語Google CloudEndpoints?

サーバサイド

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

Page 18: gcp ja night #27 Google Cloud Endpoints with Golang

使える言語Google CloudEndpoints?

サーバサイド

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

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

Page 19: gcp ja night #27 Google Cloud Endpoints with Golang

使え… ..Google CloudEndpoints?

サーバサイド

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

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

Page 20: gcp ja night #27 Google Cloud Endpoints with Golang

使える言語Google CloudEndpoints?

サーバサイド

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

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

Page 21: gcp ja night #27 Google Cloud Endpoints with Golang

使える言語Google CloudEndpoints?

クライアント

Page 22: gcp ja night #27 Google Cloud Endpoints with Golang

クライアントGoogle CloudEndpoints?

自動生成ライブラリ

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

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

Page 23: gcp ja night #27 Google Cloud Endpoints with Golang

クライアントGoogle CloudEndpoints?

自動生成ライブラリ

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

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

Page 24: gcp ja night #27 Google Cloud Endpoints with Golang

クライアントGoogle CloudEndpoints?

自動生成ライブラリ

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

NoImage

Page 25: gcp ja night #27 Google Cloud Endpoints with Golang

クライアントGoogle CloudEndpoints?

自動生成ライブラリ

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

Page 26: gcp ja night #27 Google Cloud Endpoints with Golang

Google CloudEndpoints

TRY

Page 27: gcp ja night #27 Google Cloud Endpoints with Golang

サーバサイドGoogle CloudEndpoints

TRY

準備

Page 28: gcp ja night #27 Google Cloud Endpoints with Golang

サーバサイド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

Page 29: gcp ja night #27 Google Cloud Endpoints with Golang

サーバサイドGoogle CloudEndpoints

TRY

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

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

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

Page 30: gcp ja night #27 Google Cloud Endpoints with Golang

サーバサイドGoogle CloudEndpoints

TRY

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

• NDB みたいなもの

$ go get github.com/mjibson/goon

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

Page 31: gcp ja night #27 Google Cloud Endpoints with Golang

サーバサイドGoogle CloudEndpoints

TRY

実装

Page 32: gcp ja night #27 Google Cloud Endpoints with Golang

サーバサイドGoogle CloudEndpoints

TRY

実装• 4 段階

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

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

Page 33: gcp ja night #27 Google Cloud Endpoints with Golang

サーバサイドGoogle CloudEndpoints

TRY

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

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

Page 34: gcp ja night #27 Google Cloud Endpoints with Golang

サーバサイドGoogle CloudEndpoints

TRY

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

Page 35: gcp ja night #27 Google Cloud Endpoints with Golang

サーバサイドGoogle CloudEndpoints

TRY

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

Page 36: gcp ja night #27 Google Cloud Endpoints with Golang

サーバサイドGoogle CloudEndpoints

TRY

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

Page 37: gcp ja night #27 Google Cloud Endpoints with Golang

サーバサイドGoogle CloudEndpoints

TRY

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

引数に渡してくれます。

Page 38: gcp ja night #27 Google Cloud Endpoints with Golang

サーバサイドGoogle CloudEndpoints

TRY

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

Page 39: gcp ja night #27 Google Cloud Endpoints with Golang

サーバサイドGoogle CloudEndpoints

TRY

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

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

Memcache にキャッシュ / 検索

Page 40: gcp ja night #27 Google Cloud Endpoints with Golang

サーバサイドGoogle CloudEndpoints

TRY

脇道 :goon

goon 無し

Page 41: gcp ja night #27 Google Cloud Endpoints with Golang

サーバサイドGoogle CloudEndpoints

TRY

脇道 :goon

goon 有り

Page 42: gcp ja night #27 Google Cloud Endpoints with Golang

サーバサイドGoogle CloudEndpoints

TRY

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

Page 43: gcp ja night #27 Google Cloud Endpoints with Golang

サーバサイドGoogle CloudEndpoints

TRY

Page 44: gcp ja night #27 Google Cloud Endpoints with Golang

サーバサイド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

Page 45: gcp ja night #27 Google Cloud Endpoints with Golang

サーバサイドGoogle CloudEndpoints

TRY

起動• appengine go SDK 経由

$ goapp serve

Page 46: gcp ja night #27 Google Cloud Endpoints with Golang

サーバサイドGoogle CloudEndpoints

TRY

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

er

とかに行けば試せる

Page 47: gcp ja night #27 Google Cloud Endpoints with Golang

サーバサイドGoogle CloudEndpoints

TRY

テスト

Page 48: gcp ja night #27 Google Cloud Endpoints with Golang

サーバサイドGoogle CloudEndpoints

TRY

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

$ goapp deploy

Page 49: gcp ja night #27 Google Cloud Endpoints with Golang

Google CloudEndpoints

TRY

Demohttp://goo.gl/248Dh3

Page 50: gcp ja night #27 Google Cloud Endpoints with Golang

使い所 ?Google CloudEndpoints

TRY

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

Page 51: gcp ja night #27 Google Cloud Endpoints with Golang

End