Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
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
880
4
Share
architecture of API server with golang
Gopher道場#1 LT大会での発表資料です。
golamgによるAPIサーバー設計について検討してみました
mtskhs
May 28, 2018
More Decks by mtskhs
See All by mtskhs
マジ価値を早く届ける意思決定のススメ 〜情報をそろえ、決めすぎを避ける〜/ A Decision-Making Approach for Delivering Better Products Faster
matsu0228
0
130
後進育成のしくじり〜任せるスキルとリーダーシップの両立〜
matsu0228
7
4.3k
EMがマジ価値を届けきるために考え行動したこと / Engineering Manager's thoughts and actions to deliver outcome
matsu0228
0
13k
Cloud Firestore With Go
matsu0228
0
990
Goとの歩み / History with Go
matsu0228
0
150
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.6k
expo開発におけるCI/CD / CICD on development of expo
matsu0228
0
950
Other Decks in Technology
See All in Technology
Djangoユーザが知っ得なPostgreSQL機能 - 設計の選択肢を増やす / Djang-use-PostgreSQL
soudai
PRO
0
120
AIプラットフォームを運用し続けるための可観測性
tanimuyk
4
1.1k
Platform engineering for developers, architects & the rest of us (AI agents)
danielbryantuk
0
180
先取りMaven4 ~16年ぶりのメジャーアップデート、その進化とは?~
ogiwarat
0
140
AI駆動開発が変える、大規模開発の前提 ーHuman in the Loop から Human on the Loop へ / AIE2026
visional_engineering_and_design
2
2.2k
Spring AI × MCP 入門〜AIエージェントへのツール公開、境界設計から始める最小構成 〜
yuyamiyamoto
0
210
大学生が本気でDatabricksを活用してDiscordサークルをデータ駆動させてみた
phantomjuju
1
340
Strands Agents超入門
kintotechdev
1
160
製造業のクラウド活用最適解〜AI,DXを加速するデータ基盤の作り方〜
hamadakoji
0
320
Cloud Run のアップデート 触ってみる&紹介
gre212
0
300
エンジニアは生成AIと どのように向き合うべきか? ことばの意味という観点から
verypluming
3
340
Claude Codeを組織で使いこなす— サーバサイドAIエージェント運用の実践知
techtekt
PRO
0
190
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
41
2.5k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.5k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
Designing for Performance
lara
611
70k
The Curse of the Amulet
leimatthew05
1
13k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
480
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
530
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
400
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.6k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
390
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