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
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
17年周年のWebアプリケーションにTanStack Queryを導入する / Implementing TanStack Query in a 17th Anniversary Web Application
saitolume
0
250
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
1
370
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
210
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
300
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
180
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.6k
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
180
ドメインイベント増えすぎ問題
h0r15h0
1
190
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
モバイルアプリにおける自動テストの導入戦略
ostk0069
0
110
Featured
See All Featured
Facilitating Awesome Meetings
lara
50
6.1k
It's Worth the Effort
3n
183
28k
Agile that works and the tools we love
rasmusluckow
328
21k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Why Our Code Smells
bkeepers
PRO
335
57k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
Gamification - CAS2011
davidbonilla
80
5.1k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
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Λಋೖ͢Δ͜ͱ͕తͰͳ͍͕ɺ ΑΓ҆શͰϝϯς͍͢͠ίʔυΛࢦͨ݁͠Ռ
͜ΕΒΛऔΓೖΕ͍ͨͱࢥͬͨ ·ͱΊ