Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PHPからGoフルスクラッチの戦後入社組から見た、 Pairsの開発について

yu81
August 18, 2017

PHPからGoフルスクラッチの戦後入社組から見た、 Pairsの開発について

2017/08/18 エウレカ x クラスメソッド 夜の合同勉強会 ~Go言語開発の実際のところ~ in 大阪
での発表資料です。

yu81

August 18, 2017
Tweet

More Decks by yu81

Other Decks in Technology

Transcript

  1. Copyright © 2017 eureka, Inc. All rights reserved. PHP͔ΒGoϑϧεΫϥονͷઓޙೖࣾ૊͔Βݟͨɺ Pairsͷ։ൃʹ͍ͭͯ

    2017/08/18 Τ΢ϨΧ x Ϋϥεϝιου ໷ͷ߹ಉษڧձ ~Goݴޠ։ൃͷ࣮ࡍͷͱ͜Ζ~ in େࡕ ӓҪ ༑྄
  2. Copyright © 2017 eureka, Inc. All rights reserved. ࣗݾ঺հ 2

    ೥݄ژ౎େֶཧֶ෦ೖֶ ೥݄ژ౎େֶେֶӃཧֶݚڀՊ෺ཧֶɾӉ஦෺ཧֶઐ߈म࢜՝ఔमྃ ೥݄גࣜձࣾγεςϜܭըݚڀॴೖࣾ $$ $  ೥݄ גࣜձࣾ౦ٸϋϯζϋϯζϥϘגࣜձࣾೖࣾ CBTI1)1  ೥݄גࣜձࣾΤ΢ϨΧೖࣾ (P 
  3. Copyright © 2017 eureka, Inc. All rights reserved. 3 Pairs

    GoϑϧεΫϥονͰߦͬͨ͜ͱ - PHP(CodeIgniter2)͔ΒGo΁ͷΞϓϦέʔγϣϯίʔυͷஔ͖׵͑ - WAF͸౰ॳ࠾༻ͨ͠Revel͔Βឯ༨ۂં͋ΓGin΁ɻ - DBεΩʔϚͷݟ௚͠ͱશσʔλͷϚΠάϨʔγϣϯ - MySQL - DynamoDB - ύʔςΟγϣχϯάͷڪා - 2ͭͷϦϓϨʔεΛಉ࣌ʹ(׽Β͍͠)ɻ
  4. Copyright © 2017 eureka, Inc. All rights reserved. 4 Pairs

    αʔόαΠυٕज़ελοΫ - Go(1.7) - Gin(WAF) - Circus(daemonize) - xorm(ORM) - logrus(log) - glide(vendoring) - MySQL on EC2 - Amazon Aurora - Amazon DynamoDB - Redis on Amazon ElastiCache - Google BigQuery(BI) - Sentry(error log tracking) - SemaphoreCI(CI) - etc…
  5. Copyright © 2017 eureka, Inc. All rights reserved. 6 چίʔυ(PHP)ͱͷൺֱ

    - ίʔυϕʔε͸ґવͱͯ͠େ͖͍΋ͷͷ(਺ेສߦ)ɺಡΊΔɻ - PHP൛ͷUser Model ͸΍͹͔ͬͨɻಡΊͳ͍ɻ - ౰ͨΓલ͕ͩɺڧ͍੩తܕ෇͚ʹΑΔ҆৺ײɻ - IntelliJ(Gogland)ʹΑΔαϙʔτ΋͋Δɻ - ͕ͩࣾ಺ʹ΋Vimmer͕ଟ͍ɻ - લ৬Ͱ͸PHPΛॻ͍͍͕ͯͨɺPHP൛ͷίʔυΛݟͯ΋͜Εʹ͸ߩݙͰ͖ ͳ͍ؾ͕͢Δ……ͱࢥͬͨɻ - ະܦݧͷGoͷίʔυͷํ͕·ͩಡΊΔؾ͕ͨ͠ɻ
  6. Copyright © 2017 eureka, Inc. All rights reserved. 7 ϒϥϯνઓུ

    - GitHub-Flow Λ࠾༻ - master ͕͍ͭͰ΋σϓϩΠՄೳͳঢ়ଶΛอͭ - Goʹशख़ͨ͠ਓ͕ଟ͘ͳ͔ͬͨɾٕྔ͕ࠩେ͖͔ͬͨ࣌͸ɺख़ୡऀͷ LGTM͕ग़Δ·ͰϚʔδෆՄͱ͍ͯͨ͠ɻ - શମతͳϨϕϧΞοϓʹΑΓఫഇɻ - ઃܭ͔Βࡉ͔͍Goͷ࢓༷෦෼(εϥΠεͷѻ͍ͱ͔)·Ͱ͕ͬͪΓݟ͍ͯ ͕ͨɺͩΜͩΜͱෆཁʹͳ͍ͬͯͬͨ
  7. Copyright © 2017 eureka, Inc. All rights reserved. 8 Pairs

    ϝΠϯϦϙδτϦͷύοέʔδ֓ཁ - libs - αʔϏεͷϩδοΫ΍ΞϓϦέʔγϣϯͱແؔ࿈ɾؔ࿈ͷബ͍΋ͷ - core - config, i18n, log ͳͲɻ - pairscore - ෳ਺serviceڞ௨ͷϏδωεϩδοΫ΍DBؔ࿈(entity, repository)ɻ - image,aws/{s3,sns,sqs} ͳͲ - service/pairsmain - ΞϓϦέʔγϣϯݻ༗ͷϩδοΫ - service/pairsadmin - ؅ཧը໘ - service/pairsbatch - όον
  8. Copyright © 2017 eureka, Inc. All rights reserved. 9 Pairs

    ϝΠϯϦϙδτϦͷύοέʔδ֓ཁ - લड़ͷύοέʔδߏ੒͸ϕετͳͷ͔ʁ - ͱ໰ΘΕΕ͹ɺվળͷ༨஍͕͋Δߏ੒ɻ - Ͳ͏Έͯ΋pairscore͕ɺྔతʹ΋֊૚తʹ΋fatʹͳΓ͕ͪɻ - ࣾ಺ͷଞϚΠΫϩαʔϏεͰ͸ɺDDDʹଇͬͨ΋ͷͳͲ͕͋Δɻ
  9. Copyright © 2017 eureka, Inc. All rights reserved. 10 ύοέʔδߏ੒ͷࢦ਑

    - ࠔͬͨΒެࣜɾඪ४ϥΠϒϥϦʹ໰͏ - Our CTO says too… - https://speakerdeck.com/kaneshin/go-package-guidelines
  10. Copyright © 2017 eureka, Inc. All rights reserved. 11 ϑϨʔϜϫʔΫ͕GinͰ͋Δཧ༝

    - ·ͣௐࠪͷ݁ՌRevelΛ࠾༻ͯ͠Έͨͱ͜Ζɺগͳ͘ͱ΋౰࣌ͷRevel͕࢖͍ ʹ͔ͬͨ͘ͱ͍͏ͷ͕͋Δ໛༷(͜ͷ͋ͨΓ͸఻ฉ) - Revel͸ϑϧελοΫͳϑϨʔϜϫʔΫͰɺٻΊ͍ͯͨػೳʹରͯ͠ඞཁҎ্ ʹڊେͰଟػೳͰ͋ͬͨͨΊɺ଎౓໘Ͱ΋ϚΠΫϩϑϨʔϜϫʔΫʹ܉഑͕ ্͕Δɻ - ౰࣌ͷબఆͰ͸Gin͕બ͹Εͨͱ͍͏͚ͩɻ - Revel to Gin ͷϦϓϨʔε͸1ϲ݄ͰߦΘΕͨΒ͍͠…… - ࠷ۙঃʑʹࣾ಺αʔϏε͕ϚΠΫϩαʔϏεԽ͞Ε͍ͯΔ͕ɺͦͷࡍ͸goji͕ Α͘࠾༻͞Ε͍ͯΔɻ
  11. Copyright © 2017 eureka, Inc. All rights reserved. 12 Goʹ͓͚ΔϑϨʔϜϫʔΫબఆ

    - ͦ΋ͦ΋ɺϑϨʔϜϫʔΫ͍Βͳ͍ͷͰ͸࿦͕ࣾ಺ͷҰ෦Ͱ࿩୊ʹɻ - ࠷௿ݶͷϛυϧ΢ΣΞ͕͋Ε͹े෼Ͱ͸…… - github.com/urfave/negroni ͕ؾʹͳ͍ͬͯ·͢ɻ
  12. Copyright © 2017 eureka, Inc. All rights reserved. 13 vendoring͸Ͳ͏͋Δ΂͖͔(ߟ͑ํ)

    - ͳΜͰ΋͔ΜͰ΋֎෦ϥΠϒϥϦΛ࢖͍ͬͯΔͱਏ͘ͳΔ - ΈΜͳ͍͖͍ͩͧ͢Μ͔Μ͚͍͘͡͝ - ෳ਺ͷϥΠϒϥϦ͕ผͷϥΠϒϥϦͷޓ׵ੑͷແ͍ผʑͷόʔδϣϯʹґଘ ͢Δͱ͔(͋Δ͋Δ) - খ͍͞ϥΠϒϥϦͰ͋Ε͹ɺ࣌ʹ͸ࣗΒͷϦϙδτϦʹऔΓࠐΜͰར༻͢Δ͜ ͱ΋ඞཁʹͳΔɻ - Go͸·ͩए͘ੵۃతͳΞοϓσʔτ͕ͳ͞Εɺਓޱ૿Ճ΋͜Ε͔Βͷݴޠͳͷ Ͱɺར༻͢ΔϥΠϒϥϦͷϥΠϑαΠΫϧʹରͯ͠ҙࣝతʹͳΔඞཁ͕͋Δɻ - ʮͦΕɺඪ४ϥΠϒϥϦͰΑ͘ͳ͍ʁʯͱৗʹߟ͑Δɻ
  13. Copyright © 2017 eureka, Inc. All rights reserved. 14 vendoring͸Ͳ͏͋Δ΂͖͔(πʔϧ)

    - ެࣜʹΑΔvendoringπʔϧͱͯ͠dep͕ొ৔ͨ͠ - ͕ͩɺઃఆϑΝΠϧܗ͕ࣜมߋ͞ΕΔͳͲ͕͋ͬͨ͹͔ΓͳͷͰɺ༷ࢠ ݟɻ - ॾʑམͪண͍ͨΒɺ৽͘͠࡞Δ࣌͸͜Εʹ͢Δͷ͕ਖ਼͘͠ɺ࠷΋ָʹͳ Γͦ͏ɻ - ݱࡏ࢖༻தͷglide ΋ൺֱత୯७Ͱɺಛʹ໰୊ແ͘ಈ࡞͍ͯ͠Δɻݸਓత ʹ͸͜ͷ··Ͱ΋OKɻ
  14. Copyright © 2017 eureka, Inc. All rights reserved. 15 GoͷόʔδϣϯΞοϓʹ͍ͭͯ

    - جຊతʹ͸ίϯύΠϧ͸௨ΔͷͰɺ୯ମςετ͕མͪΔΑ͏ʹͳΒͳ͚Ε ͹େৎ෉ɻ - ͕ͩɺͳ͔ͳ͔ϔϏʔͳ͜ͱ΋͋ͬͨ…… - ۩ମతʹ͸ɺGo1.5ҎԼ͔ΒGo1.6Ҏ্΁ͷΞοϓσʔτ࣌ɻ
  15. Copyright © 2017 eureka, Inc. All rights reserved. 16 GoͷόʔδϣϯΞοϓʹ͍ͭͯ

    - https://golang.org/doc/go1.6 - map΁ͷಉ࣌ॻ͖ࠐΈ͕ൃੜͨ͠৔߹ɺpanicΛى͜͢Α͏ʹͳͬͨɻ - ී௨ʹߟ͑Ε͹ࢸۃ·ͬͱ͏ͳ࢓༷ʹͳͬͨͱ͍͑Δɻ - ར༻͍ͯ͠Δ֎෦ϥΠϒϥϦ(logger, ORM)͕όʔδϣϯ͕ݹ͘ɺ͜Εʹ ରͯ͠unsafeͰɺͦΕΒͷόʔδϣϯΞοϓରԠ΋ඞཁʹͳΓͳ͔ͳ͔ ͳ͜ͱʹɻ
  16. Copyright © 2017 eureka, Inc. All rights reserved. 17 GoͷόʔδϣϯΞοϓʹ͍ͭͯ

    - ٯʹݴ͏ͱɺࠔ೉͸ͦ͏͍ͬͨͱ͜ΖʹہॴԽ͍ͯͯ͠ɺ஍ಓͳ࡞ۀͩͬ ͨɻ - -race ΦϓγϣϯΛ෇͚ͯڝ߹ঢ়ଶ͕ݕग़Ͱ͖ΔΑ͏ʹ࣮ͯ͠ߦͯ͠͸ ౰֘ՕॴΛݟ͚ͭͯ͸௚͠…… - ݱࡏ͸ 1.7 ͕ͩɺ͞ΒͳΔόʔδϣϯΞοϓͰ͸ಉ༷ͷࠔ೉͸ͳͦ͞͏ɻ - ࣮͸ผ͕݅ͪΐͬͱ͚ͩ͋Γ·͕͢……(ޱ಄ͷΈͰ)
  17. Copyright © 2017 eureka, Inc. All rights reserved. 18 configʹ͍ͭͯ

    - godotenvΛར༻ͯ͠؀ڥม਺͔Βऔಘ - ઃఆͷΧςΰϦຖʹߏ଄ମΛ४උ͠ɺΞϓϦέʔγϣϯ͔Β͸ͦͷެ։ϝ ϯόΛ௨ͯ͠ར༻ɻ
  18. Copyright © 2017 eureka, Inc. All rights reserved. 20 ϝϞϦΞϩέʔγϣϯ΍͹͍

    - ϝϞϦΞϩέʔγϣϯ͕ଟ͍ͱɺ଎౓໘Ͱ༗རͳGo΋εΫϦϓτݴޠฒͷ ଎౓ʹͳΔέʔε΋ɻ - γεςϜͷϘτϧωοΫͱͳΔཁҼ͸΋ͪΖΜଞʹ΋͋Δ͕ɺ଎౓͕Ұͭ ͷ΢ϦͰ͋ΔGoͰ͜ΕΛݪҼͱ͢ΔύϑΥʔϚϯεྼԽ͸ͳΔ΂͘ආ͚ͨ ͍ɻ - ϕϯνϚʔΫΛॻ͘ɺpprofͳͲͷϓϩϑΝΠϦϯάπʔϧΛ࢖͏ͳͲ͠ ͯɺ࠷খԽ͢Δɻ - ςετͱͱ΋ʹϕϯνϚʔΫΛॻ͘ͷ͕࠷΋ָɻ
  19. Copyright © 2017 eureka, Inc. All rights reserved. 21 ਖ਼نදݱ͕(ଟ͘ͷέʔεͰ)஗͍

    - ͜ͷ݅ʹ͍ͭͯ͸2016೥຤ʹϒϩάΛॻ͖·ͨ͠ɻ - https://developers.eure.jp/tech/golang-regexp/ - ΞϧΰϦζϜ͸͍͍͚Ͳͳ͔ͥ஗͍ɻ - ͞Βʹਖ਼نදݱͷίϯύΠϧ଎౓͕஗͍ͨΊɺ͜ͷͨΊʹύοέʔδ௚ԼͰ ਖ਼نදݱΦϒδΣΫτΛ֬อͯ͠࢖͍ճ͢ͱɺ಺෦ͷഉଞ੍ޚʹΑΔ଎౓௿ ԼʹͿͪ౰ͨΔɻ - ެࣜʹ͋ΔΑ͏ʹɺregexp.Copy() ϝιουʹͯར༻ଆ͕ίϐʔͯ͠࢖͏ࣄ Ͱղܾɻ - ϦΞϧλΠϜͰ࢖ΘΕΔճ਺ͱՄಡੑͷόϥϯεΛऔͬͯɺstringsύοέʔδͷ ؔ਺Ͱ୅ସॲཧΛߦ͏ͷ͕ݱ࣮ղɻ
  20. Copyright © 2017 eureka, Inc. All rights reserved. 23 ·ͱΊ

    - Go͸૝૾Ҏ্ʹΩϟονΞοϓ͠΍͍͢ݴޠͩͬͨ - as C/C++/C#/PHPܦݧऀ - vendoring(ύοέʔδϚωδϝϯτ)͸ɺΧλ͍πʔϧΛ࢖͍ͭͭɺґଘ͢ΔϥΠϒϥϦͷ ϥΠϑαΠΫϧ΋ߟ͑ͯར༻Λߟ͑Δɻ - ඪ४ϥΠϒϥϦͰࡁΉ΋ͷ͸ͦΕͰࡁ·͢͜ͱΛݕ౼ɻ - ύοέʔδߏ੒ʹ͍ͭͯ͸ϦϙδτϦͷαΠζʹΑΔ͕ɺඪ४ϥΠϒϥϦΛࢀߟʹ͢Δɻ - ී௨ͷεΫϦϓτݴޠͷϊϦͰॻ͘ͱࢥΘ͵ύϑΥʔϚϯεྼԽʹݟ෣ΘΕΔͷͰɺGoͷ ΍ΓํʹଇΔɻ - ͜Ε΋ެࣜͷ࢖͍ํΛ·ͣࢀߟʹ͢Δɻ - Pairs͕GoͰ׬શʹϦϓϨʔε͞Ε͍ͯͯຊ౰ʹྑ͔ͬͨɻ