Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
gRPCとgrpc-gatewayを フル活用したweb開発
Search
Go Sagawa
December 04, 2019
Programming
96
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
gRPCとgrpc-gatewayを フル活用したweb開発
Go Sagawa
December 04, 2019
More Decks by Go Sagawa
See All by Go Sagawa
GoのWebアプリ開発での DB関連トラブル
gosagawa
0
77
Errors Handling Talks at GopherCon2019
gosagawa
1
570
バッチとゴルーチンあるある
gosagawa
0
260
レガシーシステムあるある.pdf
gosagawa
0
380
Goを会社に導入して半年
gosagawa
0
130
20180228自社勉強会_プッシュ送信周りをマスターする
gosagawa
0
870
Other Decks in Programming
See All in Programming
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
140
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
34
16k
Rでドレミ/Do-Re-Mi_with_R
florets1
0
130
CodeRabbitの効果検証と過ごしてみた3ヶ月
armondando
0
200
Verilogで学ぶCPU自作入門
uyuki234
8
4.1k
dotNET_vulnclicker_intro.pdf
deka_morita
0
130
Turning Architecture into Unit Tests in the AI Era (NSSpain XIV)
steliosf
PRO
1
140
そのリトライ、死んだコネクションを使い回していませんか ── GoのHTTPクライアントとHTTP/2を実プロダクト障害から学び直す
myus4a
1
420
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
350
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
21
21k
技術的負債を組織課題として解く-増えすぎたマイクロサービスとの戦い-
reimaru
1
3k
AIに “答え“を書かせるのを やめてみた
___akari11
0
110
Featured
See All Featured
[RailsConf 2023] Rails as a piece of cake
palkan
59
7.1k
Chasing Engaging Ingredients in Design
codingconduct
0
350
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
540
The World Runs on Bad Software
bkeepers
PRO
72
12k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
940
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
280
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1.1k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
560
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
300
Transcript
gRPCとgrpc-gatewayを フル活用したweb開発 golang.tokyo #28 Dec 4, 2019 Go Sagawa and
factory,inc. @go_sagawa
About me Go Sagawa Backend engineer and factory, inc. Smartphone
app Div Twitter : @go_sagawa
構成
今日話すこと • protoをどう作成するか • grpc-gatewayをどのように活用するか grpc-gatewayの活用方法 protoをどうやって作るか?
ケース1 機能で分ける 画面数50程のアプリに対し 大まかな機能毎に10数proto 1protoに2~8API 共通で使うものが数proto
ケース1 の問題点 クライアント側もprotoからコード生成したいが、 rpcの情報が邪 魔 上手く抽象化されず、複雑になってくる
抽象化してないもの
抽象化したもの
抽象化したもの Bは他でも使うの で共通に
抽象化したもの × 書き換えが多く発生 × Bが共通で使われない × 別のprotoでC’が作れられる × 名前がかぶる ×
依存関係がわかりにくい
解決するために protoの時点で 構造化を意識してみよう!
protoを上手く構造化する
protoを上手く構造化する
改良したproto構成 画面数50程のアプリに対し 大まかな機能毎にrpc用protoと画面protoが10数 モデルprotoが50程 rpc以外はクライアント側も利用してコード生成 画面protoは極力モデルを利用する
その他のtips フォーマッタとしてclang-format を活用する
その他のtips nilになる可能性のあるユーザ定義メッセージを明示 する
その他のtips grpc-gatewayで ゼロ値も出力するように設定しておく 参考:【grpc-gateway】0, false, nullなどの値をJSON出力対象にする Https://qiita.com/cpp0302/items/2450ee93e7c5fbec28a7
その他のtips レビューをクライアント側も交えて行う →全APIモックを作り切ってから実装に入っている Backend iOS android
共通proto protoで全て表現できるのは良いですが、スキーマからAPI仕様がしれなくなるのでアン チパターンなのではと思ってます。 共通のパラメータはgRPCのメタデータでやり取りするのが良いと思います。
grpc-gatewayの活用法 単にprotobufがjsonになってデバッグしやすくなる 事がメリットではない!
grpc-gatewayの活用法 ・net.httpを利用しており、同じようにミドルウェアが かける。
grpc-gatewayの活用法 ・ログイン以外のAPIを暗号化および複合する ・メンテナンス状態にして全APIをシャットアウトする ・バージョンを判断して、強制アップデートを促す ・外部サービス(広告サービスや各種ツール)から呼ばれる、通信方式がJSONでないリ クエストの対処 ・ヘルスチェック用のAPI提供
まとめ • protoは上手く構造化して抽象化するとより活用 しやすい • grpc-gatewayはmiddlewareを使うとより強力に なる