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

Next Currency-GAEGo

sonatard
January 29, 2018

Next Currency-GAEGo

sonatard

January 29, 2018
Tweet

More Decks by sonatard

Other Decks in Programming

Transcript

  1. Server Side Engineer ͦͳͨ @sonatard • University • Linux Server

    and Network Engineer • Canon • Develop Wireless LAN Module Simulator with SystemC • Develop TCP/IP protocol stack on RTOS • Go in my free time • Mercari/Souzoh • Google App Engine Go Engineer • Mercari Atte • Next Currency • Google App Engine Go Engineer
  2. 4 ຊ೔ͷ࿩ w ελʔτΞοϓͰ͸("&(P͕͍͍ w Φʔτεέʔϧ w εϐϯΞοϓ͕ૣ͍ w 04ͷ؅ཧ͕ෆཁ

    w ϓϩμΫτͷ։ൃʹूதͰ͖Δ w ࣮ࡍʹ࢖ͬͯΈͯ w ΍͸Γศར w ݕ౼͕ඞཁͳϙΠϯτ͸ଟ͍
  3. 5 ຊ೔ͷ࿩ w ελʔτΞοϓΤϯδχΞ͕গͳ͍ w ϓϩμΫτͷ։ൃɺಛʹࠩผԽཁҼ͚ͩʹूத͍ͨ͠ w ϓϩμΫτͷ։ൃ w ΠϯϑϥͷΞʔΩςΫνϟ

    w ։ൃ؀ڥ w σϓϩΠ؀ڥ w $*؀ڥ w ςετ ϑϨʔϜϫʔΫɺॻ͖ํ  w ϑϨʔϜϫʔΫ΍ϥΠϒϥϦͷબఆ w ηΩϡϦςΟ w ΞϓϦέʔγϣϯͷΞʔΩςΫνϟݕ౼ w %#ͷઃܭ w "1*ͷઃܭ w ϏδωεϩδοΫͷίʔσΟϯά w ϏδωεϩδοΫΛ༻͍ͯΞϓϦέʔγϣϯΛߏங͢Δίʔυ w ΫϥΠΞϯτνʔϜ޲͚ͷυΩϡϝϯτ w ϩάղੳ
  4. • ٕ ज़ બ ఆ ͷ ج ຊ ํ ਑

    • ϓ ϩ δ Σ Ϋ τ ߏ ੒ • α ʔ Ϗ ε ߏ ੒ • σ ϓ ϩ Π • Ξ ʔ Ω ς Ϋ ν ϟ • ϑ Ϩ ʔ Ϝ ϫ ʔ Ϋ ɺ ϥ Π ϒ ϥ Ϧ • A P I ϓ ϩ τ ί ϧ • A P I ։ ൃ ํ ਑ • A P I Ϋ ϥ Π Ξ ϯ τ ͱ υ Ω ϡ ϝ ϯ τ • c o n f i g • η Ω ϡ Ϧ ς Ο • ։ ൃ ؀ ڥ • C I ؀ ڥ • ς ε τ • ϩ ά ղ ੳ • d a t a s t o r e ͷ ό ο Ϋ Ξ ο ϓ
  5. • ٕ ज़ બ ఆ ͷ ج ຊ ํ ਑

    • ϓ ϩ δ Σ Ϋ τ ߏ ੒ • α ʔ Ϗ ε ߏ ੒ • σ ϓ ϩ Π • Ξ ʔ Ω ς Ϋ ν ϟ • ϑ Ϩ ʔ Ϝ ϫ ʔ Ϋ ɺ ϥ Π ϒ ϥ Ϧ • A P I ϓ ϩ τ ί ϧ • A P I ։ ൃ ํ ਑ • A P I Ϋ ϥ Π Ξ ϯ τ ͱ υ Ω ϡ ϝ ϯ τ • c o n f i g • η Ω ϡ Ϧ ς Ο • ։ ൃ ؀ ڥ • C I ؀ ڥ • ς ε τ • ϩ ά ղ ੳ • d a t a s t o r e ͷ ό ο Ϋ Ξ ο ϓ
  6. • ٕ ज़ બ ఆ ͷ ج ຊ ํ ਑

    • ϓ ϩ δ Σ Ϋ τ ߏ ੒ • α ʔ Ϗ ε ߏ ੒ • σ ϓ ϩ Π • Ξ ʔ Ω ς Ϋ ν ϟ • ϑ Ϩ ʔ Ϝ ϫ ʔ Ϋ ɺ ϥ Π ϒ ϥ Ϧ • A P I ϓ ϩ τ ί ϧ • A P I ։ ൃ ํ ਑ • A P I Ϋ ϥ Π Ξ ϯ τ ͱ υ Ω ϡ ϝ ϯ τ • c o n f i g • η Ω ϡ Ϧ ς Ο • ։ ൃ ؀ ڥ • C I ؀ ڥ • ς ε τ • ϩ ά ղ ੳ • d a t a s t o r e ͷ ό ο Ϋ Ξ ο ϓ
  7. 14 αʔϏεͷߏ੒ w -ωοτϫʔΫ͸("&4&Ͱ͸ߟ͑Δඞཁ͸ͳ͍ w *1ΞυϨεΛҙࣝ͢Δ͜ͱ͸ͳ͍ w ("&ͷαʔϏε͝ͱʹࣗಈతʹυϝΠϯׂ͕ΓৼΒΕΔ w IUUQTαʔϏε໊EPUϓϩδΣΫτ໊BQQTQPUDPN

    w αʔϏεͱಠࣗʹऔಘͨ͠υϝΠϯΛඥ͚ͮΔ͜ͱ͕Մೳ BQJ BVUI BQJ BQJ YYY IUUQTBQJFYBNQMFDPN IUUQTBQJEPUQSPKFDUBQQTQPUDPN
  8. 15 αʔϏεͷߏ੒ w /$Ͱ͸.JDSPTFSWJDFTͰ͸ͳ͍͕ɺαʔϏεͷ෼ׂΛ͍ͯ͠Δ w ιʔείʔυ͸શαʔϏεڞ௨ w αʔϏεؒͰͷ௨৴͸جຊతʹͳ͠ɺϢʔβ͔ΒͷೖΓޱ͚ͩΛ෼͚͍ͯΔ w /$ͰͷαʔϏεͷར༻໨త

    w εέʔϧΞοϓͷ୯ҐɺΠϯελϯεͷೳྗ w ։ൃ༻ w EFCVHαʔϏε͸ຊ൪ʹ͸σϓϩΠ͠ͳ͍ w ೝূͷ༗ແ w BENJOαʔϏε͸ɺ(PPHMFΞΧ΢ϯτͷೝূ͕ඞཁ w αʔϏε͝ͱʹσϓϩΠ͕ඞཁʹͳΔͷͰɺ෼͚͗͢ΔͱσϓϩΠʹ͕͔͔࣌ؒΔΑ͏ ʹͳΔͷͰ஫ҙ
  9. 16 αʔϏεͷߏ੒ w ೝূͷৄࡉ app.yaml handlers: - url: /.* #

    ೝূ͋Γ login :required # HTTPSඞਢ secure: always func login(w http.ResponseWriter, r *http.Request) { ctx := appengine.NewContext(r) u := user.Current(ctx) if u == nil { url, _ := user.LoginURL(ctx, "/") fmt.Fprintf(w, `<a href="%s">Sign in or register</a>`, url) return } url, _ := user.LogoutURL(ctx, "/") fmt.Fprintf(w, `Welcome, %s! (<a href="%s">sign out</a>)`, u, url) }
  10. 17 αʔϏεͷߏ੒ w .JDSPTFSWJDFTͷඞཁੑ w ʮΦʔφʔγοϓΛ࣋ͭͨΊʯͱ͍͏ࢦ਑͸ͱͯ΋͍͍ w "1*࢓༷͑͞ڞ༗͢Ε͹ɺͦͷ಺෦ͷٕज़બఆ͸ࣗ༝ʹͳΔ w ιʔείʔυɺ"1*ͷϓϩτίϧɺ%#ͳͲ

    w ػೳʹ߹Θͤͨద੾ͳٕज़બఆ͕Մೳ w "*ج൫ͳΒ1ZUIPOɺ"1*ͳΒ(P w ෳ਺ͷαʔϏε͔Βڞ௨ج൫Λར༻Ͱ͖ΔΑ͏ʹͳΔ w ೝূɺϩά w .JDSPTFSWJDFTΛ࠾༻͢Δฐ֐ w ݕ౼ཁૉ͕૿͑Δ w ίʔυϦϙδτϦΛαʔϏε͝ͱʹ෼ׂ͢Δ΂͖͔ w ෼ׂͨ͠৔߹ɺڞ௨υϝΠϯͷมߋΛͲͷΑ͏ʹ؅ཧ͢Δ͔ w ֤αʔϏεͷϩάͷ؅ཧ͸Ͳ͏͢Δ͔
  11. 18 αʔϏεͷߏ੒ w /$ͱͯ͠͸.JDSPTFSWJDFTΛ࠾༻͍ͯ͠ͳ͍ w શһ͕ΦʔφʔγοϓΛ࣋ͯΔ૊৫ن໛Ͱ͋ΔͨΊ෼ׂ͸ඞཁͳ͍ w কདྷΛ૝ఆͨ͠ڞ௨ج൫Λਖ਼͘͠ࣄલʹઃܭ͢Δ͜ͱ͸ࠔ೉ w γεςϜ͕૊৫ʹґଘ͢Δ͜ͱ΋ϦεΫ

    w େن໛ͳมߋࢪࡦΛଧͭͨΊʹ͸ɺ૊৫Λԣஅ͢Δඞཁ͕Ͱͯ͘Δ w ෦෼࠷దʹ͍ؕΔՄೳੑ w ΠϊϕʔγϣϯͷδϨϯϚͰ͸ϦεΫͱͯ͠঺հ͞Ε͍ͯΔ w ੡඼ͷઃܭ͕૊৫ਤͦͷ΋ͷ w ՄೳͳݶΓগਓ਺ͰɺγϯϓϧͰϞϊϦγοΫͳγεςϜΛӡ༻͍͖͍ͯͨ͠ w .JDSPTFWJDFT͸໨ࢦ͢΋ͷͰ͸ͳ͘ඞཁʹഭΒΕͨΒऔΔ΂͖બ୒ࢶͷͭ
  12. • ٕ ज़ બ ఆ ͷ ج ຊ ํ ਑

    • ϓ ϩ δ Σ Ϋ τ ߏ ੒ • α ʔ Ϗ ε ߏ ੒ • σ ϓ ϩ Π • Ξ ʔ Ω ς Ϋ ν ϟ • ϑ Ϩ ʔ Ϝ ϫ ʔ Ϋ ɺ ϥ Π ϒ ϥ Ϧ • A P I ϓ ϩ τ ί ϧ • A P I ։ ൃ ํ ਑ • A P I Ϋ ϥ Π Ξ ϯ τ ͱ υ Ω ϡ ϝ ϯ τ • c o n f i g • η Ω ϡ Ϧ ς Ο • ։ ൃ ؀ ڥ • C I ؀ ڥ • ς ε τ • ϩ ά ղ ੳ • d a t a s t o r e ͷ ό ο Ϋ Ξ ο ϓ
  13. 20 σϓϩΠ w ("&ͷσϓϩΠํ๏ w αʔϏε͝ͱʹσϓϩΠΛ͢Δ w ࢦఆͨ͠όʔδϣϯͷΠϯελϯε͕࡞੒͞Εɺ63-͕ൃߦ͞ΕΔ w IUUQT\όʔδϣϯ^EPU\αʔϏε^EPU\ϓϩδΣΫτ^BQQTQPUDPN

    w όʔδϣϯ୯ҐͰCMVFHSFFOEFWFMPQNFOUΛ࣮ݱ͢Δػೳ͕ඪ४Ͱ༻ҙ w τϥϑΟοΫͷׂ߹Λࢦఆͯ͠੾Γସ͑ΒΕΔɺϩʔϧόοΫ΋༰қ w gcloud app deploy --version=${vers} ${ayml}
  14. 21 σϓϩΠ w /$ͰͷόʔδϣϯͷܾΊํ w ։ൃத͸ɺϒϥϯν໊ w σϓϩΠ͢Δ͝ͱʹ্ॻ͖͞ΕΔ w ຊ൪͸ɺ೔෇

    ίϛοτϋογϡ w σϓϩΠ͝ͱʹόʔδϣϯΛ࢒ͯ͠ɺϩʔϧόοΫՄೳͳঢ়ଶʹ͓ͯ͘͠
  15. 22 σϓϩΠ w σϓϩΠޙͷϔϧενΣοΫ w σϓϩΠεΫϦϓτͰࣗಈνΣοΫ w ࣦഊͨ͠ΒϚΠάϨʔγϣϯ͠ͳ͍ w ˌσϓϩΠͰ͖͍ͯΔ͜ͱΛ֬ೝ

    gcloud app versions list | grep "${αʔϏε} *${όʔδϣϯ}.*SERVING” || return 1 # HTTPεςʔλε 200͕ฦͬͯ͘Δ͜ͱΛ֬ೝ # init()ͷΤϥʔͳͲΛݕग़Ͱ͖Δ curl --fail https://${όʔδϣϯ}-dot-${αʔϏε}-dot-${ϓϩδΣΫτ}.appspot.com/_/health” > /dev/null 2>&1
  16. • ٕ ज़ બ ఆ ͷ ج ຊ ํ ਑

    • ϓ ϩ δ Σ Ϋ τ ߏ ੒ • α ʔ Ϗ ε ߏ ੒ • σ ϓ ϩ Π • Ξ ʔ Ω ς Ϋ ν ϟ • ϑ Ϩ ʔ Ϝ ϫ ʔ Ϋ ɺ ϥ Π ϒ ϥ Ϧ • A P I ϓ ϩ τ ί ϧ • A P I ։ ൃ ํ ਑ • A P I Ϋ ϥ Π Ξ ϯ τ ͱ υ Ω ϡ ϝ ϯ τ • c o n f i g • η Ω ϡ Ϧ ς Ο • ։ ൃ ؀ ڥ • C I ؀ ڥ • ς ε τ • ϩ ά ղ ੳ • d a t a s t o r e ͷ ό ο Ϋ Ξ ο ϓ
  17. 27 ΞʔΩςΫνϟΛݕ౼͢ΔՁ஋ͱϦεΫ w ਖ਼ղͰ͸ͳ͘ͱ΋ܾΊΔ͜ͱࣗମʹՁ஋͕͋Δ w ඞཁҎ্ʹਖ਼ղΛ௥͍ٻΊΔ͜ͱ͸ϦεΫ w ʮਖ਼͍͠%%%Λ࣮ݱ͢Δ͜ͱʯΛ໨తʹ͠ͳ͍ w ਖ਼͍͠ΞʔΩςΫνϟ͕׬੒͢Δ͜ͱ͸ͳ͍ͨΊɺແݶʹ࣌ؒΛফඅ͢ΔϦεΫ

    w ԿΛ໨తʹΞʔΩςΫνϟΛܾఆ͢Δ͔͕େ੾ w ͦͷΞʔΩςΫνϟΛબ୒ͨ͠ͳΒɺඞͣ໨తΛୡ੒͢Δ w ྫ w ໨తςετλϏϦςΟ͋͛Δ w खஈ%*Ͱ͖ΔΑ͏ʹϨΠϠʔ෼ׂΛ͢Δ w ໨తୡ੒ޙඞͣςετΛॻ͘ w ៉ྷʹͳͬͯຬ଍͢ΔͳΒػೳ։ൃΛ༏ઌ͢Δ w
  18. 29 /$ͷΞʔΩςΫνϟ w BQQMJDBUJPO૚ w υϝΠϯϞσϧɺ%#ɺ֎෦"1*ͳͲͱͷॲཧΛ·ͱΊ ͯɺΞϓϦέʔγϣϯͱͯ͠ͷػೳΛఏڙ͢Δɻ w %#͔Βऔಘ w

    υϝΠϯΛੜ੒ͯ͠ɺϝϞϦ্Ͱૢ࡞ w %#ʹอଘ BQQMJDBUJPO IBOEMFS EPNBJO *OGSBTUSVDUVSF func (a app)Buy(uid string, cid int64, amount, rate float64) error { u, err := a.RepoUser.Get(ctx, uid) // 1. DB͔Βऔಘ buy := domain.NewBuyOrder(u, cid, amount, rate) 2. υϝΠϯΛੜ੒ err := buy.Exec(ctx) // 2. υϝΠϯΛϝϞϦ্Ͱૢ࡞ err = a.RepoUser.Save(ctx, u) // 4 DBʹอଘ return nil }
  19. 30 /$ͷΞʔΩςΫνϟ w BQQMJDBUJPO૚ w BQQMJDBUJPOʹϏδωεϩδοΫΛॻ͔ͳ͍͜ͱ͕େ੾ w ҎԼͷίʔυ͸BQQMJDBUJPOʹϏδωεϩδοΫ͕࿙Ε͍ͯΔɻ w ߪೖॲཧΛςετ͢ΔͷʹBQQMJDBUJPO૚͕ඞਢʹͳΔɻ

    w %#ͷϞοΫૠೖ͕ඞਢʹͳΔςετͷϋʔυϧ্͕͕Δ func (a app)Buy(uid string, currency_id int64, amount, rate float64) error { u, err := a.RepoUser.Get(ctx, uid) // 1. DB͔Βऔಘ // ߪೖͨ͠௨՟Λ૿΍͢ b := u.GetBalance(currency_id) b.Add(amount) // ೔ຊԁΛݮΒ͢ yen := u.GetYenBalance() yen.Sub(amount * rate) err = a.RepoBalance.Save(ctx, b) // 4 DBʹอଘ return nil } ѱ͍ྫ
  20. • ٕ ज़ બ ఆ ͷ ج ຊ ํ ਑

    • ϓ ϩ δ Σ Ϋ τ ߏ ੒ • α ʔ Ϗ ε ߏ ੒ • σ ϓ ϩ Π • Ξ ʔ Ω ς Ϋ ν ϟ • ϑ Ϩ ʔ Ϝ ϫ ʔ Ϋ ɺ ϥ Π ϒ ϥ Ϧ • A P I ϓ ϩ τ ί ϧ • A P I ։ ൃ ํ ਑ • A P I Ϋ ϥ Π Ξ ϯ τ ͱ υ Ω ϡ ϝ ϯ τ • c o n f i g • η Ω ϡ Ϧ ς Ο • ։ ൃ ؀ ڥ • C I ؀ ڥ • ς ε τ • ϩ ά ղ ੳ • d a t a s t o r e ͷ ό ο Ϋ Ξ ο ϓ
  21. 34 ϑϨʔϜϫʔΫɺϥΠϒϥϦͷબఆ w 8FCΞϓϦέʔγϣϯϑϨʔϜϫʔΫʹٻΊΔػೳ w ϛυϧ΢ΣΞͷૠೖखஈ w ϧʔςΟϯάͷઃఆ w DIJIUUQTHJUIVCDPNHPDIJDIJ

    w FDIP΍HJO͸ඪ४ͷOFUIUUQͱ4FSWF)UUQϝιουͷΠϯλʔϑΣʔε͕ҟͳΔ w NJEEMFXBSFΛڬΉ৔߹ʹେن໛ͳมߋ͕ඞཁʹͳΔ r := chi.NewRouter() r.Use(func(w http.ResponseWriter, r *http.Request) { // ϩά }) r.Get("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(“welcome")) }) http.ListenAndServe(“:80", r)
  22. 35 ϑϨʔϜϫʔΫɺϥΠϒϥϦͷબఆ w HPSQ w (Pͷߏ଄ମͱ%#ͷςʔϒϧΛϚοϐϯά w HPSN w ςʔϒϧؒͷϦϨʔγϣϯΛղܾͯ͘͠ΕΔ

    w TFMFDU GSPNUBCMFΛॻ͘ඞཁ͕ͳ͍ type Product struct { Id int64 `db:"product_id, primarykey, autoincrement”` Price int64 `db:”unit_price"` } var p Product err := dbmap.SelectOne(&p, "select * from table WHERE id=? , id) p := &Product{1,2} err := dbmap.Insert(p)
  23. • ٕ ज़ બ ఆ ͷ ج ຊ ํ ਑

    • ϓ ϩ δ Σ Ϋ τ ߏ ੒ • α ʔ Ϗ ε ߏ ੒ • σ ϓ ϩ Π • Ξ ʔ Ω ς Ϋ ν ϟ • ϑ Ϩ ʔ Ϝ ϫ ʔ Ϋ ɺ ϥ Π ϒ ϥ Ϧ • A P I ϓ ϩ τ ί ϧ • A P I ։ ൃ ํ ਑ • A P I Ϋ ϥ Π Ξ ϯ τ ͱ υ Ω ϡ ϝ ϯ τ • c o n f i g • η Ω ϡ Ϧ ς Ο • ։ ൃ ؀ ڥ • C I ؀ ڥ • ς ε τ • ϩ ά ղ ੳ • d a t a s t o r e ͷ ό ο Ϋ Ξ ο ϓ
  24. 37 "1*ͷϓϩτίϧબఆ w ϓϩτίϧͷબఆ w 3&45"1* +40/31$PS(31$  w 3&45"1*ʹଇͬͯ63-ࢦ޲Ͱ)551ϝιουΛ࢖͍෼͚Δͷ͸ઃܭʹۤ࿑͢Δɻ

    +40/31$PS(31$ʁ w ("&͸(31$ະରԠ ݱࡏ  w +40/31$ ɹ(31$͕࢖͍͍ͨ w ͳͥ(31$Λ࢖͍͍͔ͨʁ w 1SPUPDPM#V⒎FSTͷఆٛϑΝΠϧ w ΫϥΠΞϯτͱ"1*ͷιʔείʔυΛࣗಈੜ੒ w (31$Ͱ͋Δඞཁ͸ͳ͍
  25. 38 "1*ͷϓϩτίϧબఆ w ϓϩτίϧͷબఆ1SPUPDPM#V⒎FSTPO)551 w 3&45"1* +40/31$ (31$ͷ͍͍ͱ͜औΓ w 63-Ͱ࣮ߦ͢ΔϝιουΛࢦఆɻ

    w IUUQBQJFYNBQMFDPNW&YDIBOHF#VZ w )551ϝιου͸1045ͷΈ w ϦΫΤετɺϨεϙϯεɺϝιουͷܕ͸ɺ1SPUPDPM#V⒎FSTͰఆٛ w (31$ͱಉ༷ʹ(31$ͷπʔϧ܈Ͱιʔείʔυੜ੒Մೳ w 1SPUPDPM#V⒎FSTͷఆٛϑΝΠϧ͔Β(P 4XJGU 5ZQF4DSJQU +BWBͷίʔυੜ੒ w message BuyRequest{ int currency_id = 1; double amount = 2; double rate = 3; } message BuyResponse {} rpc Buy(BuyRequest) returns (BuyResponse);
  26. 39 "1*ͷϓϩτίϧબఆ1SPUPDPM#V⒎FSTPO)551ͱैདྷٕज़ͷൺֱ w 3&45"1*ͱൺֱ w ྑ͍఺31$ͳͷͰ"1*ઃܭ͕༰қ w 3&45Ͱ͸ɺ)551ϝιουɺ63-ͷݕ౼͕ඞཁ w 1VUϝιου

    W&YDIBOHF#BMBODF w 31$ͳΒɺϝιου͸1PTUݻఆɻ63-͸ίʔυ্ͷϝιουʹରԠɻ w W&YDOBIHF#VZ w +40/31$ͱൺֱ w ྑ͍఺1SPUPDPM#V⒎FSTʹΑΓɺΫϥΠΞϯτ͸"1*ͷมߋΛίϯύΠϧ࣌ʹݕग़ w ѱ͍఺ඪ४Ͱ͸ͳ͍ͷͰɺଞࣾ΍ެ։"1*ʹ͸޲͔ͳ͍ w (31$ͱൺֱ w ྑ͍఺)551ͳͷͰैདྷͷ؀ڥͰɺैདྷͷίʔυ͕ಈ͘ɻ w (31$͸ɺ(31$ͷίʔυΛॻ͘ඞཁ͕͋Δɻ w ѱ͍఺(31$ͷػೳ͕࢖͑ͳ͍ TUSFBN
  27. 43 "1*ͷϓϩτίϧબఆ w (31$PS)551PO1SPUPDPM#V⒎FSTͷݕ౼ w ໨త͸  w ߏ଄Խ͞ΕͨఆٛϑΝΠϧ͔ΒιʔείʔυΛੜ੒͍ͨ͠ w

    PS w TUSFBN͕࢖͍͍ͨɻͦͷଞ(31$ݻ༗ͷػೳΛ࢖͍͍ͨɻ w े෼ͳ։ൃϦιʔε͕͋Δ͔ w (31$Λ࠾༻ͯ͠ैདྷͷγεςϜ΍ίʔυ͕࢖͑ͳ͍ͱ͖ରԠՄೳ͔
  28. • ٕ ज़ બ ఆ ͷ ج ຊ ํ ਑

    • ϓ ϩ δ Σ Ϋ τ ߏ ੒ • α ʔ Ϗ ε ߏ ੒ • σ ϓ ϩ Π • Ξ ʔ Ω ς Ϋ ν ϟ • ϑ Ϩ ʔ Ϝ ϫ ʔ Ϋ ɺ ϥ Π ϒ ϥ Ϧ • A P I ϓ ϩ τ ί ϧ • A P I ։ ൃ ํ ਑ • A P I Ϋ ϥ Π Ξ ϯ τ ͱ υ Ω ϡ ϝ ϯ τ • c o n f i g • η Ω ϡ Ϧ ς Ο • ։ ൃ ؀ ڥ • C I ؀ ڥ • ς ε τ • ϩ ά ղ ੳ • d a t a s t o r e ͷ ό ο Ϋ Ξ ο ϓ
  29. 45 "1*։ൃํ਑ w "1*͸มΘΔલఏͰɺΫϥΠΞϯτͷ։ൃΛࢭΊͳ͍Α͏ʹॻ͍͍ͯ͘ w ճ͘Β͍େ෯ͳมߋ͓ئ͍͍ͯ͠Δ w ࠷ॳ͔Β࢓༷Λ໢ཏ͢Δ͜ͱ͸ແཧ w ΫϥΠΞϯτνʔϜʹ͸ɺʮϦϦʔε·Ͱ͸มΘΓଓ͚Δͷڐͯ͠ʯ

    w ٯʹΫϥΠΞϯτ͔Βͷཁ๬͸ۃྗड͚Δ w ࢓༷͕໢ཏ͞ΕΔॠؒ͸ϦϦʔε௚લ w ϦϦʔε௚લ͕Ұ൪͍͍"1*Λ࡞Δ͜ͱ͕Ͱ͖Δ w ͦΕ·Ͱ௚͠ଓ͚Δ w ྑ͍΋ͷΛ࡞Γ͍ͨͱ͍͏ҙ͕ࣝڞ༗͞Ε͍ͯΔϝϯόʔͳͷͰڐ͞ΕΔ w ײँ
  30. • ٕ ज़ બ ఆ ͷ ج ຊ ํ ਑

    • ϓ ϩ δ Σ Ϋ τ ߏ ੒ • α ʔ Ϗ ε ߏ ੒ • σ ϓ ϩ Π • Ξ ʔ Ω ς Ϋ ν ϟ • ϑ Ϩ ʔ Ϝ ϫ ʔ Ϋ ɺ ϥ Π ϒ ϥ Ϧ • A P I ϓ ϩ τ ί ϧ • A P I ։ ൃ ํ ਑ • A P I Ϋ ϥ Π Ξ ϯ τ ͱ υ Ω ϡ ϝ ϯ τ • c o n f i g • η Ω ϡ Ϧ ς Ο • ։ ൃ ؀ ڥ • C I ؀ ڥ • ς ε τ • ϩ ά ղ ੳ • d a t a s t o r e ͷ ό ο Ϋ Ξ ο ϓ
  31. 50 "1*ΫϥΠΞϯτͱυΩϡϝϯτ w ϨεϙϯεΛม਺ʹઃఆͰ͖ΔͷͰɺ"DDFTT5PLFOͷ؅ཧ΋͓खܰ w "DDFTT5PLFOͷϨεϙϯε w ϨεϙϯεΛ؀ڥม਺ʹઃఆ w ϦΫΤετΛૹΔࡍͷɺ)551ϔομʔͰ؀ڥม਺Λࢀর

    var res = JSON.parse(responseBody); postman.setEnvironmentVariable("ACCESS_TOKEN", res.token); { "token": “accesstokennnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn" }
  32. 51 "1*ΫϥΠΞϯτͱυΩϡϝϯτ w 1PTUNBOΛνʔϜͰڞ༗͢Δ͜ͱͰɺαʔόαΠυɺΫϥΠΞϯταΠυͷΤϯδχΞ ͕ؾܰʹ"1*Λୟ͘͜ͱ͕Մೳ w ։ൃதͷ໰୊ൃੜ࣌ͷ੾Γ෼͚͕༰қʹͳΔ w 1PTUNBO͔Βୟ͍ͯ΋໰୊͕͋Ε͹αʔόʹ໰୊͋ΔՄೳੑ͕ߴ͍ w

    ΫϥΠΞϯτΤϯδχΞ΋αʔόαΠυΤϯδχΞʹ໰୊ڀ໌ΛཔΈ΍͘͢ͳΔ w ࣮ࡍʹಈ͘΋ͷ͕͋ΔͷͰɺυΩϡϝϯτͷ୅ΘΓʹͳΔ w 1SPUPDPM#V⒎FSTͷఆٛϑΝΠϧͱ߹Θͤͯ࢓༷ͷཧղ͕Մೳ w Θ͔Βͳ͍ͱ͜Ζ͕͋Ε͹ฉ͍ͯ΋Βͬͯղܾ w 4XBHHFS΋ඞཁͳ͍
  33. • ٕ ज़ બ ఆ ͷ ج ຊ ํ ਑

    • ϓ ϩ δ Σ Ϋ τ ߏ ੒ • α ʔ Ϗ ε ߏ ੒ • σ ϓ ϩ Π • Ξ ʔ Ω ς Ϋ ν ϟ • ϑ Ϩ ʔ Ϝ ϫ ʔ Ϋ ɺ ϥ Π ϒ ϥ Ϧ • A P I ϓ ϩ τ ί ϧ • A P I ։ ൃ ํ ਑ • A P I Ϋ ϥ Π Ξ ϯ τ ͱ υ Ω ϡ ϝ ϯ τ • c o n f i g • η Ω ϡ Ϧ ς Ο • ։ ൃ ؀ ڥ • C I ؀ ڥ • ς ε τ • ϩ ά ղ ੳ • d a t a s t o r e ͷ ό ο Ϋ Ξ ο ϓ
  34. 53 DPOpH w ։ൃϓϩδΣΫτ͝ͱʹDPOpHΛઃఆ͍ͨ͠ w 42-ͷ઀ଓઌͳͲ w DPOpHͷ࣮ݱํ๏ w ZBNM΍UPNMͰಠࣗͷDPOpHϞδϡʔϧΛ࡞Δʁ

    w ("&Ͱ͸BQQZBNMͷ؀ڥม਺ʹઃఆ͢Δͷ͕ηΦϦʔ w DPOpHͷ੾Γସ͑ํ๏ w DPOpHZBNMΛ؀ڥ͝ͱʹ࡞੒ͯ͠ɺBQQZBNM͔ΒJODMVEF͢Δ w σϓϩΠ࣌ʹDPOpHZBNMΛγϯϘϦοΫϦϯΫͰ੾Γସ͑Δ env_variables: MYSQL_CONNECTION : user:pass@cloudsql(project:asia-northeast1:xxxxx)/yyy includes: - config.yaml
  35. 54 DPOpH w DPOpHͷಡΈࠐΈํ w ؀ڥม਺ΛίʔυʹಡΈࠐΉͨΊʹFOWDPOpHΛ࠾༻ɻ w DPOpHͷ஋ΛඞཁʹͳͬͨλΠϛϯάͰ؀ڥม਺͔ΒಡΈࠐΉͷͰ͸ͳ͘ɺJOJU࣌ʹ ߏ଄ମʹಡΈࠐΜͰ͓͘ w

    type Config struct { MysqlConnection string `required:"true" split_words:"true"` var C Config func Setup() { if err := envconfig.Process(“prefix", &C); err != nil { panic(err) } }
  36. • ٕ ज़ બ ఆ ͷ ج ຊ ํ ਑

    • ϓ ϩ δ Σ Ϋ τ ߏ ੒ • α ʔ Ϗ ε ߏ ੒ • σ ϓ ϩ Π • Ξ ʔ Ω ς Ϋ ν ϟ • ϑ Ϩ ʔ Ϝ ϫ ʔ Ϋ ɺ ϥ Π ϒ ϥ Ϧ • A P I ϓ ϩ τ ί ϧ • A P I ։ ൃ ํ ਑ • A P I Ϋ ϥ Π Ξ ϯ τ ͱ υ Ω ϡ ϝ ϯ τ • c o n f i g • η Ω ϡ Ϧ ς Ο • ։ ൃ ؀ ڥ • C I ؀ ڥ • ς ε τ • ϩ ά ղ ੳ • d a t a s t o r e ͷ ό ο Ϋ Ξ ο ϓ
  37. 57 ηΩϡϦςΟ w $MPVE,.4 w ݸਓ৘ใɺ֎෦ͷ"1*ΩʔͳͲྲྀग़ͯ͠͸͍͚ͳ͍΋ͷ͸$MPVE,.4Λ࢖ͬͯ҉߸Խ্ͨ͠Ͱ อଘ͢Δɻ w ҉߸Խ͢Δ͏͑Ͱͷൿີ伴Λಠࣗʹ༻ҙͯ͠؅ཧ͢Δඞཁ͕ͳ͍ɻ w

    ௚઀EBUBTUPSFͷσʔλ͕ྲྀग़ͯ͠΋҉߸Խ͞Ε͍ͯΔͨΊ໰୊͸ى͖ͳ͍ɻ w 伴ͷϩʔςʔτΛఆظతʹ͢Δ͜ͱͰɺྲྀग़ͨ͠ࡍͷϦεΫΛ௿ݮɻ w 伴ͷϩʔςʔτͷ࠶҉߸ԽͳͲ΋Մೳɻ w ΦʔφʔݖݶΛ࣋ͬͨ(PPHMFΞΧ΢ϯτͱύεϫʔυ͕ྲྀग़ͨ͠৔߹ͷΈ໰୊ͱͳΔɻ w $MPVE,.4ࣗମͷೝূ͸("&ͷαʔϏεΞΧ΢ϯτͰߦ͏ɻ w ݖݶΛ࣋ͬͨαʔϏεΞΧ΢ϯτͷΩʔΛੜ੒͍ͯ͠ͳ͚Ε͹ɺ֎෦͔Β$MPVE,.4Λୟ ͘͜ͱ΋Ͱ͖ͳ͍ɻ w ΋͠αʔϏεଆͷϢʔβͷΞΧ΢ϯτͱύεϫʔυ͕࿙Εͨ৔߹ʹ΋ɺର৅Ϣʔβͷݸਓ৘ใ ͔͠ྲྀग़͸͠ͳ͍ɻ w ৄࡉ͸ެࣜυΩϡϝϯτͱHDQVHOPVIBVΛࢀর w IUUQTHJUIVCDPNHDQVHOPVIBVUSFFNBTUFSDMPVELNTQPFNJOUSPEVDUJPO w
  38. • ٕ ज़ બ ఆ ͷ ج ຊ ํ ਑

    • ϓ ϩ δ Σ Ϋ τ ߏ ੒ • α ʔ Ϗ ε ߏ ੒ • σ ϓ ϩ Π • Ξ ʔ Ω ς Ϋ ν ϟ • ϑ Ϩ ʔ Ϝ ϫ ʔ Ϋ ɺ ϥ Π ϒ ϥ Ϧ • A P I ϓ ϩ τ ί ϧ • A P I ։ ൃ ํ ਑ • A P I Ϋ ϥ Π Ξ ϯ τ ͱ υ Ω ϡ ϝ ϯ τ • c o n f i g • η Ω ϡ Ϧ ς Ο • ։ ൃ ؀ ڥ • C I ؀ ڥ • ς ε τ • ϩ ά ղ ੳ • d a t a s t o r e ͷ ό ο Ϋ Ξ ο ϓ
  39. 59 ։ൃ؀ڥ w ৽نͷ։ൃऀ͕ೖͬͨࡍͷ։ൃ؀ڥߏங w (Pͷ։ൃ؀ڥ w HPJNQPSUT w EFQ

    w ΤσΟλɺ*%&͸ࣗ༝ w 7JN w (P-BOE w HPMBOHUPLZPˌͰ(P։ൃ؀ڥ(PHMBOEͷϥΠϒσϞΛݟ͖ͯͨ w IUUQUFDINFSDBSJDPNFOUSZ w
  40. 60 ։ൃ؀ڥ w ৽نͷ։ൃऀ͕ೖͬͨࡍͷ("&։ൃ؀ڥߏங w ίϚϯυϥΠϯͰ͢΂ͯΛ࣮ݱ w ($1ͷίϯιʔϧΛ৮Βͳ͍ w ίϚϯυͳΒखॱ͕࢒ΓɺεΫϦϓτͱͯ͠ߏ੒؅ཧ͕Մೳ

    w *OGSBTUSVDUVSFBTDPEFɺίϚϯυΛௐ΂Ε͹ԿΛ΍͍ͬͯΔ͔Θ͔Δ w 8JLJͳͲʹखॱΛ·ͱΊΔඞཁ΋ͳ͍ w ($1ίϯιʔϧ͸೔ʑߋ৽͞ΕΔͨΊυΩϡϝϯτͷ௥ै͕೉͍͠ w ؀ڥߏங࣌ʹ౓͚ͩॱ൪ʹίϚϯυΛୟ͚ͩ͘ͳͷͰTIFMMTDSJQUͰ࣮ݱ w 04ͷঢ়ଶ؅ཧ͢ΔΘ͚Ͱ͸ͳ͍ͨΊEPDLFS BOTJCMF DIFG͸ར༻͠ͳ͍
  41. • ٕ ज़ બ ఆ ͷ ج ຊ ํ ਑

    • ϓ ϩ δ Σ Ϋ τ ߏ ੒ • α ʔ Ϗ ε ߏ ੒ • σ ϓ ϩ Π • Ξ ʔ Ω ς Ϋ ν ϟ • ϑ Ϩ ʔ Ϝ ϫ ʔ Ϋ ɺ ϥ Π ϒ ϥ Ϧ • A P I ϓ ϩ τ ί ϧ • A P I ։ ൃ ํ ਑ • A P I Ϋ ϥ Π Ξ ϯ τ ͱ υ Ω ϡ ϝ ϯ τ • c o n f i g • η Ω ϡ Ϧ ς Ο • ։ ൃ ؀ ڥ • C I ؀ ڥ • ς ε τ • ϩ ά ղ ੳ • d a t a s t o r e ͷ ό ο Ϋ Ξ ο ϓ
  42. 62 $*؀ڥ w $*πʔϧʹٻΊΔػೳ w %PDLFSJNBHF͕࢖͑Δ w Ωϟογϡػೳ͕͋Δ w ߴ଎

    w ෳࡶͳػೳΛ$*πʔϧʹٻΊͳ͍+FOLJOT͓͡͞Μ͕ඞཁʹͳΔ͜ͱΛආ͚Δ
  43. 63 $*؀ڥ w $JSDMF$* w USBWJT͔ΒҠͬͨΒഒʹ w $JSDMF$*ΑΓ଎͍4BB4͕ͰͨΒҠߦ͍ͯ͘͠ w ("&(P༻ͷ$*ΠϝʔδNFSDBSJEPDLFSBQQFOHJOFHP

    w HPBQQUFTU΍HDMPVEʹΑΔσϓϩΠ͕Մೳ w ෆ଍͍ͯ͠Δπʔϧ͸NFSDBSJBQQFOHJOFHPΛϕʔεΠϝʔδͱͯ͠ಠࣗΠϝʔδΛ࡞੒ w $JSDMF$*্ͰπʔϧͷΠϯετʔϧ͸͠ͳ͍ w ςετ͕஗͘ͳΔ w ஗͘ͳΒͳ͍ͨΊʹΩϟογϡ͢ΔॲཧΛॻ͘ͱDJSDMFDJDPOpHZBNM͕େ͖͘ͳΔ w $*πʔϧ΁ͷґଘ͕େ͖͘ͳΔ
  44. 65 $*؀ڥ w ద੾ʹ੹຿Λ෼ׂ w $JSDMF$* DJSDMFDJDPOpHZBNM  w ࣮ߦ؀ڥͷࢦఆ

    w ϦϙδτϦͷDMPOF w $*΁ͷࢦࣔ w $JFDMF$*͸ϩʔΧϧͰ࣮ߦՄೳ w DJFDMFDJCVJME w $*؀ڥͷσόοάʹศར version: 2 jobs: build: working_directory: /go/src/github.com/org/proj docker: - image: sonatard/appengine-go steps: - checkout - run: command: make ci
  45. 66 $*؀ڥ w ద੾ʹ੹຿Λ෼ׂ w %PDLFSJNBHF w ࣮ߦ؀ڥͷߏஙʹಛԽ͢Δ w Πϝʔδʹ͸ϓϩδΣΫτͷݻ༗৘ใ͸ࡌͤͳ͍

    w 伴 w $JSDMF$*ͷ؀ڥม਺ʹઃఆ w ιʔείʔυ w (JUIVCϦϙδτϦʹ഑ஔ w ެ։ՄೳͳΠϝʔδʹ͢Δ w ೝূɺηΩϡϦςΟͷۤ࿑͕ͳ͘ͳΔ w FROM mercari/appengine-go:1.8-slim ←ϕʔεΠϝʔδʹ͢Δ ARG PROTOC_VERSION=3.4.0 RUN curl -fo protoc.zip -sSL “https://github.com/protobuf/releases/protoc-${PROTOC_VERSION}-linux-x86_64.zip" // ུ
  46. 67 $*؀ڥ w ద੾ʹ੹຿Λ෼ׂ w .BLFpMF w ਓؒͱTIFMMTDSJQUΛܨ͙ΠϯλʔϑΣʔε w NBLFpMFʹॲཧ͸ॻ͔ͣɺTIFMMTDSJQUͷίϚϯυΛ࣮ߦ͢Δ͚ͩ

    w $*Ͱ࣮ߦ͢ΔίϚϯυͱ։ൃͰ࣮ߦ͢ΔίϚϯυ͸ՄೳͳݶΓಉ౳ʹ͢Δ w dep: dep ensure -vendor-only -v test: gen test.sh $(GOLIST) ci: ci.sh deploy_qa: gen deploy.sh qa $(ALL_SERVICES) deploy_prod: gen deploy.sh qa $(ALL_SERVICES)
  47. 68 $*؀ڥ w ద੾ʹ੹຿Λ෼ׂ w TIFMMTDSJQU w ۩ମతͳॲཧΛهड़͢Δ GOLIST=$(goapp list

    ./... | grep -v vendor) test.sh ${GOLIST} branch=$(git rev-parse --abbrev-ref @) if [ "x${branch}" = "xmaster" ] ; then deploy_target="qa" else # ։ൃϒϥϯν͸σϓϩΠ͠ͳ͍ return 0 fi all_services="api batch pre default" deploy.sh "${deploy_target}" “${all_services}"
  48. • ٕ ज़ બ ఆ ͷ ج ຊ ํ ਑

    • ϓ ϩ δ Σ Ϋ τ ߏ ੒ • α ʔ Ϗ ε ߏ ੒ • σ ϓ ϩ Π • Ξ ʔ Ω ς Ϋ ν ϟ • ϑ Ϩ ʔ Ϝ ϫ ʔ Ϋ ɺ ϥ Π ϒ ϥ Ϧ • A P I ϓ ϩ τ ί ϧ • A P I ։ ൃ ํ ਑ • A P I Ϋ ϥ Π Ξ ϯ τ ͱ υ Ω ϡ ϝ ϯ τ • c o n f i g • η Ω ϡ Ϧ ς Ο • ։ ൃ ؀ ڥ • C I ؀ ڥ • ς ε τ • ϩ ά ղ ੳ • d a t a s t o r e ͷ ό ο Ϋ Ξ ο ϓ
  49. 70 ςετ w 5BCMF%SJWFO5FTU w ςετέʔεΛ໢ཏ͢Δ͜ͱ͕໌ࣔ͞ΕΔ w UFTUJGZͳͲͷςετϑϨʔϜϫʔΫ͸࢖Θͳ͍ w ̍ϝιουʹଟͯ͘ճ͘Β͍ͷ஋ൺֱͳͷͰɺૉ௚ʹΤϥʔग़ྗΛࣗ෼Ͱॻ͘

    w ߏ଄ମͷൺֱͷͨΊʹHPDNQΛར༻ w IUUQTHJUIVCDPNHPPHMFHPDNQ w ςετ༻ͷ֎෦πʔϧΛۃྗ࢖Θͳ͍ w πʔϧΛֶͿίετ w ςετΛॻ͘ϋʔυϧͷ૿Ճ
  50. • ٕ ज़ બ ఆ ͷ ج ຊ ํ ਑

    • ϓ ϩ δ Σ Ϋ τ ߏ ੒ • α ʔ Ϗ ε ߏ ੒ • σ ϓ ϩ Π • Ξ ʔ Ω ς Ϋ ν ϟ • ϑ Ϩ ʔ Ϝ ϫ ʔ Ϋ ɺ ϥ Π ϒ ϥ Ϧ • A P I ϓ ϩ τ ί ϧ • A P I ։ ൃ ํ ਑ • A P I Ϋ ϥ Π Ξ ϯ τ ͱ υ Ω ϡ ϝ ϯ τ • c o n f i g • η Ω ϡ Ϧ ς Ο • ։ ൃ ؀ ڥ • C I ؀ ڥ • ς ε τ • ϩ ά ղ ੳ • d a t a s t o r e ͷ ό ο Ϋ Ξ ο ϓ
  51. • ٕ ज़ બ ఆ ͷ ج ຊ ํ ਑

    • ϓ ϩ δ Σ Ϋ τ ߏ ੒ • α ʔ Ϗ ε ߏ ੒ • σ ϓ ϩ Π • Ξ ʔ Ω ς Ϋ ν ϟ • ϑ Ϩ ʔ Ϝ ϫ ʔ Ϋ ɺ ϥ Π ϒ ϥ Ϧ • A P I ϓ ϩ τ ί ϧ • A P I ։ ൃ ํ ਑ • A P I Ϋ ϥ Π Ξ ϯ τ ͱ υ Ω ϡ ϝ ϯ τ • c o n f i g • η Ω ϡ Ϧ ς Ο • ։ ൃ ؀ ڥ • C I ؀ ڥ • ς ε τ • ϩ ά ղ ੳ • d a t a s t o r e ͷ ό ο Ϋ Ξ ο ϓ
  52. • ٕ ज़ બ ఆ ͷ ج ຊ ํ ਑

    • ϓ ϩ δ Σ Ϋ τ ߏ ੒ • α ʔ Ϗ ε ߏ ੒ • σ ϓ ϩ Π • Ξ ʔ Ω ς Ϋ ν ϟ • ϑ Ϩ ʔ Ϝ ϫ ʔ Ϋ ɺ ϥ Π ϒ ϥ Ϧ • A P I ϓ ϩ τ ί ϧ • A P I ։ ൃ ํ ਑ • A P I Ϋ ϥ Π Ξ ϯ τ ͱ υ Ω ϡ ϝ ϯ τ • c o n f i g • η Ω ϡ Ϧ ς Ο • ։ ൃ ؀ ڥ • C I ؀ ڥ • ς ε τ • ϩ ά ղ ੳ • d a t a s t o r e ͷ ό ο Ϋ Ξ ο ϓ
  53. 77 ·ͱΊ w /FYU$VSSFODZͷߏ੒ w (PPHMF"QQ&OHJOF(P EBUBTUPSF $MPVE42- w ϑϨʔϜϫʔΫHPDIJ

    ϧʔςΟϯάͱϛυϧ΢ΣΞ  w ߏ଄ମͱ%#ςʔϒϧͷόΠϯυHPSQ w ϨΠϠʔυΞʔΩςΫνϟ )BOEMFS "QQMJDBUJPO %PNBJO *OGSBTUSVDUVSF  w (31$ޓ׵ͷಠࣗ)551ϕʔεͷ31$ w DPOpHFOWDPOpH w $JSDMF$* NFSDBSJEPDLFSBQQFOHJOFHP QSPUPDΛՃ͑ͨΠϝʔδ  w 5FTUඪ४ͷUFTUJOHύοέʔδ HPDNQ w σόοά༻"1*ΫϥΠΞϯτ1PTUNBO w ػີ৘ใͷ؅ཧ$MPVE,.4 w ղੳ#JH2VFSZ w 4UBDL%SJWFS͔ΒΠϯϙʔτ w EBUBTUPSF͔ΒΠϯϙʔτ GBWDMJQETCR