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
architecture of API server with golang
Search
mtskhs
May 28, 2018
Technology
900
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
architecture of API server with golang
Gopher道場#1 LT大会での発表資料です。
golamgによるAPIサーバー設計について検討してみました
mtskhs
May 28, 2018
More Decks by mtskhs
See All by mtskhs
解決策を教えても次期リーダーは育たない ─ 器の発達に伴走するために / Partnering with leaders in their vertical development
matsu0228
1
760
マジ価値を早く届ける意思決定のススメ 〜情報をそろえ、決めすぎを避ける〜/ A Decision-Making Approach for Delivering Better Products Faster
matsu0228
1
180
後進育成のしくじり〜任せるスキルとリーダーシップの両立〜
matsu0228
7
4.4k
EMがマジ価値を届けきるために考え行動したこと / Engineering Manager's thoughts and actions to deliver outcome
matsu0228
0
14k
Cloud Firestore With Go
matsu0228
0
1k
Goとの歩み / History with Go
matsu0228
0
170
ReactNativeにおけるパフォーマンスチューニング/ Performance tuning in ReactNative
matsu0228
2
1.7k
スタートアップチームで学んだエンジニアの心構え / The attitude of the engineer who learned from the start-up team
matsu0228
1
1.9k
Goにおける API Client実装パターン / API Client implementation pattern in Go
matsu0228
8
8.7k
Other Decks in Technology
See All in Technology
顧客に向き合う開発組織へ。リアーキテクチャとフィーチャーチーム化で挑む組織改革
safie
0
2.4k
AI時代の「技術的負債」の変質ー概念の終焉と再解釈、エージェントと共に向かう先
nwiizo
1
3.2k
.NET WebAssemblyで実現するクライアントサイドAI推論:NuGetからViteまで、2つのエコシステムを繋ぐビルド戦略
yamachu
1
560
事業課題から技術的負債に向き合う
sansantech
PRO
2
2.3k
積み重なった技術負債への挑戦 〜初手としての全社ゴト化〜
techtekt
PRO
0
1.6k
今話題のAI「Jev」って何? 宇宙最速で学ぶ会
minorun365
PRO
30
19k
What the customer really needed
kawaguti
PRO
3
220
Oracle Cloud Infrastructure(OCI):Onboarding Session(はじめてのOCI/Oracle Supportご利⽤ガイド)
oracle4engineer
PRO
2
20k
30座EKS, 180次升級淬煉的EKS Upgrade Skill 的歷程
eric8230
0
210
Von-Neumann Machines, Dreams & The Futures of IT
ufried
0
120
EventBridge に「合流」はない ― サーバーレスのワークフローを育てるということ / No Join in EventBridge
yusukeshimizu
2
480
ADKで始める業務改善 - AIエージェント開発時の考えと設計
harappa80
2
270
Featured
See All Featured
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
610
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
710
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
The Cult of Friendly URLs
andyhume
79
7k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
260
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
910
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Odyssey Design
rkendrick25
PRO
2
810
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
470
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
Thoughts on Productivity
jonyablonski
76
5.4k
Transcript
golangにおける APIアーキテクチャ設計 2018/5/28 @ gopher dojo LT Hisayuki Matsuki
自己紹介 松木 久幸 https://github.com/matsu0228 2 Server Side Engineer Python/Django Ruby
on Rails
What’s this? • Agenda 1. アーキテクチャ設計 2. golangで書いてみた 3. 課題点/疑問点
• 話すこと ◦ 概念的な話 ◦ packageの分け方 / interface ◦ サンプルコード(https://github.com/matsu0228/go_sandbox/tree/master/cleanArch) • 話さないこと ◦ どのようなFramework/Libraryを使うか ◦ 例:database接続には◦◦を使う 3
1-1.APIアーキテクチャ設計 • ある程度の規模のAPIサーバーをgolangで構築する ◦ GET /product/1795, POST /product/new ◦ GET
/campaign/5235 ◦ … • 要件 ◦ 修正時の影響範囲が限定的 かつ ◦ テストしやすい(databaseまわりなど) 4
1-2.Clean Architecture • 依存関係は一方方向(外から内側) • 上記に矛盾が発生しないよう、DIP(依存関係逆転の原則) ◦ Go: IFを活用 原文:
https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-architecture.html 5
2-1. レイヤー • Entity ◦ structを定義 • Usecase ◦ ビジネスロジックを定義
◦ <= IF:product.repository • Repository ◦ database操作を定義 ◦ <= database/sql (ref: sqlx) • HttpDeliver ◦ webサーバーを定義 ◦ <= IF:product.usecase 6
2-2. レイヤー:Entity • Entity ◦ structを定義 7
2-3. レイヤー:Repository • Repository ◦ database操作を定義 ◦ <= database/sql (ref:
sqlx) 8
2-4. レイヤー:Usecase • Usecase ◦ ビジネスロジックを定義 ◦ <= IF:product.repository 9
2-5. レイヤー:Usecase • 矛盾が発生しないよう、DIP(依存関係逆転の原則) 10
2-6. ディレクトリ構成 • 1st dir: エンドポイント種別 ◦ campaign, product, ...
,common • 2nd dir: layer ◦ -> 影響を限定的に 11
2-7. Usecaseのテスト • DatabaseをMockで差し替えて、ビジネスロジックのテストがし やすい ◦ <= IF:product.repository 12
3.課題点/疑問点 • そもそも1プロセスで、複数APIエンドポイント提供する? • 小規模なAPIでは、複雑なコードになりデメリットも大きそう(慣 れの問題?) ◦ 修正ごとに、IFを調整したり ◦ 配置場所が悪いと拡張性が悪くなりそうだったり
13
まとめ • ある程度の規模のAPIサーバーを、golangで構築する際の設計 について検討 ◦ 具体的なサンプルコードを基に、概要を説明 ◦ サンプルコード(https://github.com/matsu0228/go_sandbox/tree/master/cleanArch) • golangにおけるinterfaceの利用例を提示
• このLTをきっかけに、アーキテクチャ設計について知見を深め られればと 14