Slide 1

Slide 1 text

Go੡MVCΞϓϦέʔγϣϯͷ ΞʔΩςΫνϟΛมߋ͢Δ 2020.01.29 howtv.go - @inari111

Slide 2

Slide 2 text

• ܊ ୓࠸ • Twitter: @inari111 • GitHub: @inari111 • Go / Layered Architecture / Protocol buffers • 2019.04~ hey (Coiney) • πέ෷͍ ࣗݾ঺հ

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

ి࿩൪߸Λೖྗ SMSૹ৴ λοϓͯ͠ಉҙͰ πέ෷͍׬ྃ 2ϲ݄Ҏ಺ʹίϯϏχ౳Ͱࢧ෷͍

Slide 5

Slide 5 text

• ࠓͷπέ෷͍ͷΞʔΩςΫνϟ • ࠓͷΞʔΩςΫνϟͷ໰୊఺ • ৽͍͠ΞʔΩςΫνϟ(Ծ) ࠓ೔࿩͢͜ͱ

Slide 6

Slide 6 text

ϑϨʔϜϫʔΫ͸revelΛ࢖༻ app ᵓᴷᴷ client ᵓᴷᴷ controllers ᵓᴷᴷ library ᵓᴷᴷ models ᵓᴷᴷ routes ᵓᴷᴷ services ᵋᴷᴷ views ࠓͷΞʔΩςΫνϟ $POUSPMMFS 4FSWJDF .PEFM .PEFMͷؔ਺ݺͼग़͠ $MJFOU 4.4ૹ৴ ֎෦"1* ϏδωεϩδοΫ ӬଓԽॲཧ

Slide 7

Slide 7 text

•ModelԼ͕ؔ਺ʹͳ͍ͬͯΔՕॴ͕ଟ͍ • ؔ਺໊͕௕͘ͳͬͯ͠·͏ • GetConsumerByPhoneNumber, UpdateSettlementToXXX… • ؔ਺ͳͷͰͲͷService͔ΒͰ΋ݺͼग़ͤͯ͠·͏ • mockԽ͕εϚʔτʹͰ͖ͳ͍ •Modelͷίʔυ͕ଟ͘ͳ͖ͬͯͨ •Model͕domain΍infraͷ໾ׂΛ୲͍ͬͯΔ •ӬଓԽͷॲཧͱυϝΠϯϩδοΫ͕෼཭Ͱ͖͍ͯͳ͍ ໰୊఺

Slide 8

Slide 8 text

•ίʔυྔ͕૿͖͑ͯͯɺϝϯςͮ͠Β͍Օॴ͕ग़͖ͯͨ •υϝΠϯϩδοΫͱӬଓԽॲཧΛ෼͚Δ͜ͱͰؔ৺ࣄͷ෼཭ Λߦ͍͍ͨ ͳͥΞʔΩςΫνϟΛมߋ͍ͨ͠ͷ͔

Slide 9

Slide 9 text

৽͍͠ ΞʔΩςΫνϟ(Ծ) $POUSPMMFS %PNBJO 4FSWJDF .PEFM 3FQPTJUPSZݺͼग़͠ $MJFOU 4.4ૹ৴ ֎෦"1* ϏδωεϩδοΫ 3FQPTJUPSZ*OUFSGBDF %#Ϟσϧ 3FQPTJUPSZ࣮૷ 2VFSZ4FSWJDF*OUFSGBDF 2VFSZ4FSWJDF࣮૷ ࢀরܥϞσϧ υϝΠϯϞσϧ

Slide 10

Slide 10 text

• υϝΠϯϞσϧ • ϏδωεϩδοΫ • Repositoryͷinterface Domain $POUSPMMFS %PNBJO 4FSWJDF .PEFM 3FQPTJUPSZݺͼग़͠ ϏδωεϩδοΫ 3FQPTJUPSZ*OUFSGBDF %#Ϟσϧ 3FQPTJUPSZ࣮૷ 2VFSZ4FSWJDF*OUFSGBDF 2VFSZ4FSWJDF࣮૷ ࢀরܥϞσϧ υϝΠϯϞσϧ

Slide 11

Slide 11 text

domain/consumer/repository.go

Slide 12

Slide 12 text

services/consumer.go

Slide 13

Slide 13 text

• DBϞσϧ • Repositoryͷ࣮૷ • υϝΠϯϞσϧ 㲗 DBϞσϧ • Query Serviceͷ࣮૷ Model $POUSPMMFS %PNBJO 4FSWJDF .PEFM 3FQPTJUPSZݺͼग़͠ ϏδωεϩδοΫ 3FQPTJUPSZ*OUFSGBDF %#Ϟσϧ 3FQPTJUPSZ࣮૷ 2VFSZ4FSWJDF*OUFSGBDF 2VFSZ4FSWJDF࣮૷ ࢀরܥϞσϧ υϝΠϯϞσϧ

Slide 14

Slide 14 text

• ෳ਺ू໿ʹ·͕ͨΔσʔλΛऔಘ ͢ΔͨΊʹಋೖ • ServiceʹࢀরܥϞσϧɺ interfaceΛఆٛ • interfaceͷ࣮૷͸Modelʹஔ͘ Query Service $POUSPMMFS %PNBJO 4FSWJDF .PEFM 3FQPTJUPSZݺͼग़͠ ϏδωεϩδοΫ 3FQPTJUPSZ*OUFSGBDF %#Ϟσϧ 3FQPTJUPSZ࣮૷ 2VFSZ4FSWJDF*OUFSGBDF 2VFSZ4FSWJDF࣮૷ ࢀরܥϞσϧ υϝΠϯϞσϧ

Slide 15

Slide 15 text

• ৽نػೳ௥ՃΛࢭΊͣʹ͍͍ײ͡ʹϦϑΝΫλΛਐΊ͍ͯ͘ʹ͸ • ෳ਺Repositoryʹ·͕ͨΔτϥϯβΫγϣϯ • ServiceͰτϥϯβΫγϣϯுΔ͔͠ͳ͍…ʁ • ίʔυྔ͕૿͑ͯ͘ΔͱMVCͩͱͭΒ͍…ͱࢥ͏ ೰Έ

Slide 16

Slide 16 text

• RepositoryͷಋೖʹΑΓӬଓԽॲཧͱυϝΠϯϩδοΫ ͷ෼཭Λߦ͏͜ͱʹͨ͠ • Query ServiceΛ࡞੒ͯ͠ෳ਺ू໿ʹ·͕ͨΔσʔλΛ औಘ͢Δ͜ͱʹͨ͠ • DDD΍CQRSΛಋೖ͢Δ͜ͱ͕໨తͰ͸ͳ͍͕ɺ ΑΓ҆શͰϝϯς͠΍͍͢ίʔυΛ໨ࢦͨ݁͠Ռ ͜ΕΒΛऔΓೖΕ͍ͨͱࢥͬͨ ·ͱΊ