Save 37% off PRO during our Black Friday Sale! »

Go製MVCアプリケーションのアーキテクチャを変更する

8012e7370021675c336021ce7530b50a?s=47 inari111
January 29, 2020

 Go製MVCアプリケーションのアーキテクチャを変更する

8012e7370021675c336021ce7530b50a?s=128

inari111

January 29, 2020
Tweet

Transcript

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

  2. • ܊ ୓࠸ • Twitter: @inari111 • GitHub: @inari111 •

    Go / Layered Architecture / Protocol buffers • 2019.04~ hey (Coiney) • πέ෷͍ ࣗݾ঺հ
  3. None
  4. ి࿩൪߸Λೖྗ SMSૹ৴ λοϓͯ͠ಉҙͰ πέ෷͍׬ྃ 2ϲ݄Ҏ಺ʹίϯϏχ౳Ͱࢧ෷͍

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

  6. ϑϨʔϜϫʔΫ͸revelΛ࢖༻ app ᵓᴷᴷ client ᵓᴷᴷ controllers ᵓᴷᴷ library ᵓᴷᴷ models

    ᵓᴷᴷ routes ᵓᴷᴷ services ᵋᴷᴷ views ࠓͷΞʔΩςΫνϟ $POUSPMMFS 4FSWJDF .PEFM .PEFMͷؔ਺ݺͼग़͠ $MJFOU 4.4ૹ৴ ֎෦"1* ϏδωεϩδοΫ ӬଓԽॲཧ
  7. •ModelԼ͕ؔ਺ʹͳ͍ͬͯΔՕॴ͕ଟ͍ • ؔ਺໊͕௕͘ͳͬͯ͠·͏ • GetConsumerByPhoneNumber, UpdateSettlementToXXX… • ؔ਺ͳͷͰͲͷService͔ΒͰ΋ݺͼग़ͤͯ͠·͏ • mockԽ͕εϚʔτʹͰ͖ͳ͍

    •Modelͷίʔυ͕ଟ͘ͳ͖ͬͯͨ •Model͕domain΍infraͷ໾ׂΛ୲͍ͬͯΔ •ӬଓԽͷॲཧͱυϝΠϯϩδοΫ͕෼཭Ͱ͖͍ͯͳ͍ ໰୊఺
  8. •ίʔυྔ͕૿͖͑ͯͯɺϝϯςͮ͠Β͍Օॴ͕ग़͖ͯͨ •υϝΠϯϩδοΫͱӬଓԽॲཧΛ෼͚Δ͜ͱͰؔ৺ࣄͷ෼཭ Λߦ͍͍ͨ ͳͥΞʔΩςΫνϟΛมߋ͍ͨ͠ͷ͔

  9. ৽͍͠ ΞʔΩςΫνϟ(Ծ) $POUSPMMFS %PNBJO 4FSWJDF .PEFM 3FQPTJUPSZݺͼग़͠ $MJFOU 4.4ૹ৴ ֎෦"1*

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

    .PEFM 3FQPTJUPSZݺͼग़͠ ϏδωεϩδοΫ 3FQPTJUPSZ*OUFSGBDF %#Ϟσϧ 3FQPTJUPSZ࣮૷ 2VFSZ4FSWJDF*OUFSGBDF 2VFSZ4FSWJDF࣮૷ ࢀরܥϞσϧ υϝΠϯϞσϧ
  11. domain/consumer/repository.go

  12. services/consumer.go

  13. • DBϞσϧ • Repositoryͷ࣮૷ • υϝΠϯϞσϧ 㲗 DBϞσϧ • Query

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

    $POUSPMMFS %PNBJO 4FSWJDF .PEFM 3FQPTJUPSZݺͼग़͠ ϏδωεϩδοΫ 3FQPTJUPSZ*OUFSGBDF %#Ϟσϧ 3FQPTJUPSZ࣮૷ 2VFSZ4FSWJDF*OUFSGBDF 2VFSZ4FSWJDF࣮૷ ࢀরܥϞσϧ υϝΠϯϞσϧ
  15. • ৽نػೳ௥ՃΛࢭΊͣʹ͍͍ײ͡ʹϦϑΝΫλΛਐΊ͍ͯ͘ʹ͸ • ෳ਺Repositoryʹ·͕ͨΔτϥϯβΫγϣϯ • ServiceͰτϥϯβΫγϣϯுΔ͔͠ͳ͍…ʁ • ίʔυྔ͕૿͑ͯ͘ΔͱMVCͩͱͭΒ͍…ͱࢥ͏ ೰Έ

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

    ͜ΕΒΛऔΓೖΕ͍ͨͱࢥͬͨ ·ͱΊ