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
connect-goとsqlboilerで構築するクリーンアーキテクチャ
Search
hirocy
September 26, 2024
Programming
0
1.5k
connect-goとsqlboilerで構築するクリーンアーキテクチャ
「PIXIV DEV MEETUP 2024」LT発表資料
https://conference.pixiv.co.jp/2024/dev-meetup
hirocy
September 26, 2024
Tweet
Share
Other Decks in Programming
See All in Programming
API Platform 4.2: Redefining API Development
soyuka
0
200
詳解!defer panic recover のしくみ / Understanding defer, panic, and recover
convto
0
250
Reading Rails 1.0 Source Code
okuramasafumi
0
250
AIと私たちの学習の変化を考える - Claude Codeの学習モードを例に
azukiazusa1
11
4.4k
さようなら Date。 ようこそTemporal! 3年間先行利用して得られた知見の共有
8beeeaaat
3
1.5k
個人軟體時代
ethanhuang13
0
330
go test -json そして testing.T.Attr / Kyoto.go #63
utgwkk
3
320
意外と簡単!?フロントエンドでパスキー認証を実現する WebAuthn
teamlab
PRO
2
780
複雑なドメインに挑む.pdf
yukisakai1225
5
1.2k
AI時代のUIはどこへ行く?
yusukebe
18
9.1k
知っているようで知らない"rails new"の世界 / The World of "rails new" You Think You Know but Don't
luccafort
PRO
1
190
為你自己學 Python - 冷知識篇
eddie
1
350
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.9k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
139
34k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
jQuery: Nuts, Bolts and Bling
dougneiner
64
7.9k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
15k
Six Lessons from altMBA
skipperchong
28
4k
Git: the NoSQL Database
bkeepers
PRO
431
66k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.7k
Agile that works and the tools we love
rasmusluckow
330
21k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
36
2.5k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
285
14k
Transcript
connect-goとsqlboilerで構築する クリーンアーキテクチャ hirocy
{広告なんでも, pixiv Ads}チーム エンジニア 💼 23新卒/広告開発 ❤ Go言語/VTuber https://x.com/hir0cy hirocy
話すこと • クリーンアーキテクチャとは • connect-go・sqlboilerとは • 広告管理サーバーを設計した際の最終的なディレクトリ 構成の紹介 • connect-go・sqlboilerをクリーンアーキテクチャに取
り込む上での工夫
話さないこと • connect-goとsqlboilerの使い方 • 基本的なクリーンアーキテクチャの実装 Ask the Speakerで僕と握手!
クリーンアーキテクチャ とは?
クリーンアーキテクチャ • Robert C. Martinが2012年に提唱したアーキテクチャ • 4層のレイヤー構造 ◦ Enterprise Business
Rules(domain層) ◦ Application Business Rules(usecase層) ◦ Interface Adapters(interface層) ◦ Frameworks & Drivers(infrastructure層)
クリーンアーキテクチャ • Robert C. Martinが2012年に提唱したアーキテクチャ • 4層のレイヤー構造 ◦ Enterprise Business
Rules(domain層) ◦ Application Business Rules(usecase層) ◦ Interface Adapters(interface層) ◦ Frameworks & Drivers(infrastructure層)
connect-go・sqlboiler とは?
connect-goの特徴 • The Go implementation of Connect: Protobuf RPC that
works. • ConnectというプロトコルのGo実装 • Protobufで記述された通信の定義に基づいてGoのパッ ケージを生成
sqlboilerの特徴 • Generate a Go ORM tailored to your database
schema. • 実際のDBスキーマからGoのORM(Object-Relational Mapping)をパッケージとして生成
どちらもパッケージ生成
クリーンアーキテクチャ のどこに生成?
〜広告管理サーバーの場合〜 最終的なディレクトリ構成
最終的なディレクトリ構成 "esakik/clean-architecture-python" (https://github.com/esakik/clean-architecture-python) より引用
最終的なディレクトリ構成
なぜinterface層に生成? • 例えばconnectについて... ◦ interface層 ▪ 通信の中身を見るレイヤー ◦ infrastructure層 ▪
通信について記述するレイヤー →ハンドラーやDBのクエリをinterface層で記述したい
connect-go・sqlboiler を扱う上での工夫
sqlboilerを扱う上での工夫 • sqlboilerは独自の型とdomainとの変換が必要 ◦ converterを実装して対応 • sqlboilerの実行には*sql.DBが必要 ◦ infrastructure層で接続を張った*sql.DBを返すよう に実装
connect-goを扱う上での工夫 • 決められたHandlerの型 で実装する必要がある • interactorから presenterを呼ぶ流れと 相性が悪い "esakik/clean-architecture-python" (https://github.com/esakik/clean-architecture-python)
より引用
connect-goを扱う上での工夫 controllerから presenterを呼び出す
connect-goを扱う上での工夫 controllerから presenterを呼び出す
connect-goを扱う上での工夫 "クリーンアーキテクチャの Presenter が分かりにくいのは MVC 2 じゃないから" (https://qiita.com/os1ma/items/c02af5b7783b58165c8d) より引用
まとめ • connect-goとsqlboilerはinterface層に生成 • presenterをcontrollerから呼び出すように改変 • 都度リファクタリングをすることでより良いアーキテク チャにしている • Goの互助会ブースやAsk
the Speakerも是非!