Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
architecture of API server with golang
Search
mtskhs
May 28, 2018
Technology
4
850
architecture of API server with golang
Gopher道場#1 LT大会での発表資料です。
golamgによるAPIサーバー設計について検討してみました
mtskhs
May 28, 2018
Tweet
Share
More Decks by mtskhs
See All by mtskhs
マジ価値を早く届ける意思決定のススメ 〜情報をそろえ、決めすぎを避ける〜/ A Decision-Making Approach for Delivering Better Products Faster
matsu0228
0
58
後進育成のしくじり〜任せるスキルとリーダーシップの両立〜
matsu0228
7
3.9k
EMがマジ価値を届けきるために考え行動したこと / Engineering Manager's thoughts and actions to deliver outcome
matsu0228
0
10k
Cloud Firestore With Go
matsu0228
0
960
Goとの歩み / History with Go
matsu0228
0
130
ReactNativeにおけるパフォーマンスチューニング/ Performance tuning in ReactNative
matsu0228
2
1.6k
スタートアップチームで学んだエンジニアの心構え / The attitude of the engineer who learned from the start-up team
matsu0228
1
1.8k
Goにおける API Client実装パターン / API Client implementation pattern in Go
matsu0228
8
8.5k
expo開発におけるCI/CD / CICD on development of expo
matsu0228
0
900
Other Decks in Technology
See All in Technology
会社紹介資料 / Sansan Company Profile
sansan33
PRO
11
390k
Amazon Connect アップデート! AIエージェントにMCPツールを設定してみた!
ysuzuki
0
120
M&Aで拡大し続けるGENDAのデータ活用を促すためのDatabricks権限管理 / AEON TECH HUB #22
genda
0
210
ZOZOの独自性を生み出す「似合う4大要素」の開発サイクル
zozotech
PRO
0
110
AIBuildersDay_track_A_iidaxs
iidaxs
4
1k
Fashion×AI「似合う」を届けるためのWEARのAI戦略
zozotech
PRO
2
1.1k
New Relic 1 年生の振り返りと Cloud Cost Intelligence について #NRUG
play_inc
0
190
高度サイバー人材育成専科(後半)
nomizone
0
480
特別捜査官等研修会
nomizone
0
530
re:Invent2025 3つの Frontier Agents を紹介 / introducing-3-frontier-agents
tomoki10
0
360
[Data & AI Summit '25 Fall] AIでデータ活用を進化させる!Google Cloudで作るデータ活用の未来
kirimaru
0
220
Amazon Quick Suite で始める手軽な AI エージェント
shimy
1
1.6k
Featured
See All Featured
Docker and Python
trallard
47
3.7k
Designing for Performance
lara
610
69k
Producing Creativity
orderedlist
PRO
348
40k
Prompt Engineering for Job Search
mfonobong
0
120
Designing Experiences People Love
moore
143
24k
The SEO identity crisis: Don't let AI make you average
varn
0
32
Git: the NoSQL Database
bkeepers
PRO
432
66k
Site-Speed That Sticks
csswizardry
13
1k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
359
30k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
1
23
RailsConf 2023
tenderlove
30
1.3k
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