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
4
810
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
EMがマジ価値を届けきるために考え行動したこと / Engineering Manager's thoughts and actions to deliver outcome
matsu0228
0
6.8k
Cloud Firestore With Go
matsu0228
0
900
Goとの歩み / History with Go
matsu0228
0
120
ReactNativeにおけるパフォーマンスチューニング/ Performance tuning in ReactNative
matsu0228
2
1.5k
スタートアップチームで学んだエンジニアの心構え / The attitude of the engineer who learned from the start-up team
matsu0228
1
1.7k
Goにおける API Client実装パターン / API Client implementation pattern in Go
matsu0228
7
8.1k
expo開発におけるCI/CD / CICD on development of expo
matsu0228
0
860
SpoLiveの爆速開発を支えるGAE/Goノウハウ / Practice of GAE&Go supporting SpoLive super fast development
matsu0228
1
230
Report of AgileTestingDays2018
matsu0228
0
530
Other Decks in Technology
See All in Technology
自動化の第一歩 -インフラ環境構築の自動化について-
smt7174
1
120
『ささAI』ネタづくりをささえるAI📝 (にぼしいわし担当:GIFTech2025)
masapyon1212
0
110
AndroidアプリエンジニアもMCPを触ろう
kgmyshin
2
650
AI駆動で進化する開発プロセス ~クラスメソッドでの実践と成功事例~ / aidd-in-classmethod
tomoki10
1
1k
Part1 GitHubってなんだろう?その2
tomokusaba
2
720
[新卒向け研修資料] テスト文字列に「うんこ」と入れるな(2025年版)
infiniteloop_inc
4
14k
LINE 購物幕後推手
line_developers_tw
PRO
0
430
Global Azure2025(GitHub Copilot ハンズオン)
tomokusaba
2
720
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
5.5k
LangfuseではじめるAIアプリのLLMトレーシング
codenote
0
140
Azure & DevSecOps
kkamegawa
2
180
エンジニアリングで組織のアウトカムを最速で最大化する!
ham0215
1
300
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
172
14k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
31
1.2k
StorybookのUI Testing Handbookを読んだ
zakiyama
30
5.7k
Adopting Sorbet at Scale
ufuk
76
9.4k
Done Done
chrislema
184
16k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
357
30k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
179
53k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
137
33k
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