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
Go製MVCアプリケーションのアーキテクチャを変更する
Search
inari111
January 29, 2020
Programming
0
2.5k
Go製MVCアプリケーションのアーキテクチャを変更する
inari111
January 29, 2020
Tweet
Share
Other Decks in Programming
See All in Programming
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
150
役立つログに取り組もう
irof
28
9.6k
最新TCAキャッチアップ
0si43
0
140
距離関数を極める! / SESSIONS 2024
gam0022
0
280
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.7k
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
290
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
250
Outline View in SwiftUI
1024jp
1
320
みんなでプロポーザルを書いてみた
yuriko1211
0
260
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.1k
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
2
660
Featured
See All Featured
Git: the NoSQL Database
bkeepers
PRO
427
64k
BBQ
matthewcrist
85
9.3k
The Language of Interfaces
destraynor
154
24k
KATA
mclloyd
29
14k
Side Projects
sachag
452
42k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Bash Introduction
62gerente
608
210k
Designing the Hi-DPI Web
ddemaree
280
34k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Transcript
GoMVCΞϓϦέʔγϣϯͷ ΞʔΩςΫνϟΛมߋ͢Δ 2020.01.29 howtv.go - @inari111
• ܊ ࠸ • Twitter: @inari111 • GitHub: @inari111 •
Go / Layered Architecture / Protocol buffers • 2019.04~ hey (Coiney) • πέ͍ ࣗݾհ
None
ి൪߸Λೖྗ SMSૹ৴ λοϓͯ͠ಉҙͰ πέ͍ྃ 2ϲ݄ҎʹίϯϏχͰࢧ͍
• ࠓͷπέ͍ͷΞʔΩςΫνϟ • ࠓͷΞʔΩςΫνϟͷ • ৽͍͠ΞʔΩςΫνϟ(Ծ) ࠓ͢͜ͱ
ϑϨʔϜϫʔΫrevelΛ༻ app ᵓᴷᴷ client ᵓᴷᴷ controllers ᵓᴷᴷ library ᵓᴷᴷ models
ᵓᴷᴷ routes ᵓᴷᴷ services ᵋᴷᴷ views ࠓͷΞʔΩςΫνϟ $POUSPMMFS 4FSWJDF .PEFM .PEFMͷؔݺͼग़͠ $MJFOU 4.4ૹ৴ ֎෦"1* ϏδωεϩδοΫ ӬଓԽॲཧ
•ModelԼ͕ؔʹͳ͍ͬͯΔՕॴ͕ଟ͍ • ໊͕ؔ͘ͳͬͯ͠·͏ • GetConsumerByPhoneNumber, UpdateSettlementToXXX… • ؔͳͷͰͲͷService͔ΒͰݺͼग़ͤͯ͠·͏ • mockԽ͕εϚʔτʹͰ͖ͳ͍
•Modelͷίʔυ͕ଟ͘ͳ͖ͬͯͨ •Model͕domaininfraͷׂΛ୲͍ͬͯΔ •ӬଓԽͷॲཧͱυϝΠϯϩδοΫ͕Ͱ͖͍ͯͳ͍
•ίʔυྔ͕૿͖͑ͯͯɺϝϯςͮ͠Β͍Օॴ͕ग़͖ͯͨ •υϝΠϯϩδοΫͱӬଓԽॲཧΛ͚Δ͜ͱͰؔ৺ࣄͷ Λߦ͍͍ͨ ͳͥΞʔΩςΫνϟΛมߋ͍ͨ͠ͷ͔
৽͍͠ ΞʔΩςΫνϟ(Ծ) $POUSPMMFS %PNBJO 4FSWJDF .PEFM 3FQPTJUPSZݺͼग़͠ $MJFOU 4.4ૹ৴ ֎෦"1*
ϏδωεϩδοΫ 3FQPTJUPSZ*OUFSGBDF %#Ϟσϧ 3FQPTJUPSZ࣮ 2VFSZ4FSWJDF*OUFSGBDF 2VFSZ4FSWJDF࣮ ࢀরܥϞσϧ υϝΠϯϞσϧ
• υϝΠϯϞσϧ • ϏδωεϩδοΫ • Repositoryͷinterface Domain $POUSPMMFS %PNBJO 4FSWJDF
.PEFM 3FQPTJUPSZݺͼग़͠ ϏδωεϩδοΫ 3FQPTJUPSZ*OUFSGBDF %#Ϟσϧ 3FQPTJUPSZ࣮ 2VFSZ4FSWJDF*OUFSGBDF 2VFSZ4FSWJDF࣮ ࢀরܥϞσϧ υϝΠϯϞσϧ
domain/consumer/repository.go
services/consumer.go
• DBϞσϧ • Repositoryͷ࣮ • υϝΠϯϞσϧ 㲗 DBϞσϧ • Query
Serviceͷ࣮ Model $POUSPMMFS %PNBJO 4FSWJDF .PEFM 3FQPTJUPSZݺͼग़͠ ϏδωεϩδοΫ 3FQPTJUPSZ*OUFSGBDF %#Ϟσϧ 3FQPTJUPSZ࣮ 2VFSZ4FSWJDF*OUFSGBDF 2VFSZ4FSWJDF࣮ ࢀরܥϞσϧ υϝΠϯϞσϧ
• ෳूʹ·͕ͨΔσʔλΛऔಘ ͢ΔͨΊʹಋೖ • ServiceʹࢀরܥϞσϧɺ interfaceΛఆٛ • interfaceͷ࣮Modelʹஔ͘ Query Service
$POUSPMMFS %PNBJO 4FSWJDF .PEFM 3FQPTJUPSZݺͼग़͠ ϏδωεϩδοΫ 3FQPTJUPSZ*OUFSGBDF %#Ϟσϧ 3FQPTJUPSZ࣮ 2VFSZ4FSWJDF*OUFSGBDF 2VFSZ4FSWJDF࣮ ࢀরܥϞσϧ υϝΠϯϞσϧ
• ৽نػೳՃΛࢭΊͣʹ͍͍ײ͡ʹϦϑΝΫλΛਐΊ͍ͯ͘ʹ • ෳRepositoryʹ·͕ͨΔτϥϯβΫγϣϯ • ServiceͰτϥϯβΫγϣϯுΔ͔͠ͳ͍…ʁ • ίʔυྔ͕૿͑ͯ͘ΔͱMVCͩͱͭΒ͍…ͱࢥ͏ Έ
• RepositoryͷಋೖʹΑΓӬଓԽॲཧͱυϝΠϯϩδοΫ ͷΛߦ͏͜ͱʹͨ͠ • Query ServiceΛ࡞ͯ͠ෳूʹ·͕ͨΔσʔλΛ औಘ͢Δ͜ͱʹͨ͠ • DDDCQRSΛಋೖ͢Δ͜ͱ͕తͰͳ͍͕ɺ ΑΓ҆શͰϝϯς͍͢͠ίʔυΛࢦͨ݁͠Ռ
͜ΕΒΛऔΓೖΕ͍ͨͱࢥͬͨ ·ͱΊ