Perl to Go

Perl to Go

YAPC::Tokyo 2019 で発表した内容になります

2d524d56b2ddff49363c995f2d795da0?s=128

Yuji Shimada

January 26, 2019
Tweet

Transcript

  1. 1.
  2. 6.
  3. 7.

    ίυδЀύ • ΀Ͳ Go ͡ • Perl Monger ͢ Golang

    ΨতΗΞ͜͹ͼ䦒΁Ϝϫ͹͵;ͩΣ • Go ΄᥺承՛䯭ͽ਍Ό Perl ;΄ፘ晅ᅩ • Web API Ψ֢͹ͼΕΞ͜ • ϓφϕΨ䨗ͥ • Docker Ϡϸϖͭͼ㵕ͯ͡ • Δ;Η
  4. 11.

    WebςЄϝЄ;ͭͼΕ͵ Go (2) • πЀϓϗ΅ηЀϤϹ;ྲΏΡ;涥ͥΑͿ΄֗φϧϐμ΄ςЄϝЄӤͽ㵕̵ͭ͡ හ܈뺶හጯݣ㪔ΏΡΞ͜΀ොݻ • ςЄϝЄ΄φϧϐμ͚֗͢͵Ηṛ᭛ͽ㵕̵֢ͭ͡ͺϮϯϷ㵁ሲΘΞ͚᥺承͢࿢ ΗΟ΢Ρ •

    ͫΟ΁πЀϓϗᛔ֛΄ςαχΘੜͫͥͭ͵Α͜͢Ӟᛱጱ΁᩸㵕᭛ଶ͢Ӥ͢Ρ͵ Ηੜͫͥͭ͵͚ • φμϷϤϕ᥺承΄Ξ͜΁϶Ѐόαϭ͢஠ᥝ΀Θ΄΅හጯMBΨ᩻͞ͼͭΔ͚᭿ ͧ͵͚
  5. 12.

    WebςЄϝЄ;ͭͼΕ͵ Go (3) • Go ΄䁰ݳ΅ • ϝαϗϷΨ֢౮ͯ΢Ά϶Ѐόαϭ͢஠ᥝ΀͚͵ΗπЀϓϗ΄ςαχΨಪ ͞Ρͩ;͢ͽͣΡ •

    ฦ᭗΁䨗ͥͶͧͽ Java Κ C ΁܃䤔ͯΡΑͿṛ᭛͡ͺ፜ϮϯϷͽ㵕֢ͯΡ • gorutine ΁ΞΠ̵ᛔᆐ;㵁ሲጱ΁CPU;ᑮ樌ΨڥአͯΡͩ;͢ͽͣΡ • Ӥ懿΄ᇙ䖀΅ηЀϤϹͽΘ㱢֖΁㰕ͥ
  6. 13.

    πϫЀϖ϶αЀϑЄϸ;ͭͼΕ͵ Go (1) • 樄咲ᘏ͡ΟͯΡ; • CPUΚϮϯϷ΄௔ᚆ͢Ӥ͢͹͵΄; go ΄πЀϞαϸᛔ֛͢ṛ ᭛΀͵Η

    LL ;晉ᜋ͢΀͚ϹϦϸͽ墋㶨΁πЄϖΨ䨗͚ͼ手ͯ ͩ;͢ͽͣΡ΄ͽφμϷϤϕఽ憝ͽπЄϖΨ䨗ͥͩ;͢਻ฃ • ل樄ͯΡ;ͣΘμϺφπЀϞαϸ͢਻ฃ΀΄ͽϝαϗϷΨኞ ౮ͭͼ晒୮΀䁰ಅ΁ίϐϤͭͼͧ͠ΆΞ͚
  7. 17.
  8. 18.

    ίυδЀύ • ΀Ͳ Go ͡ • Perl Monger ͢ Golang

    ΨতΗΞ͜͹ͼ䦒΁Ϝϫ͹͵;ͩΣ • Go ΄᥺承՛䯭ͽ਍Ό Perl ;΄ፘ晅ᅩ • Go ͽ๋ṛ΄ Web API Ψ֢͹ͼΕΞ͜Ѻ • Go ͽ͚͚ے仂ϓφϕΨ䨗ͥʹѺ • ͚͚ఽͮ΁ϠϸϖͭͼϷϷЄφͯΡʹѺ • Δ;Η
  9. 19.

    Perl Monger ͢ Golang ΨতΗΞ͜͹ͼ䦒 ΁Ϝϫ͹͵;ͩΣ • ίυδЀύ • CPAN

    ͢΀͚ • $GOPATH ͡Οᭈ΢Ο΢΀͚ • ϶αϣ϶Ϸ΄ᓕቘොဩ͢ΖͰ͚ • ηЄςϷЀνϑЄϸ͢΀͚
  10. 20.

    CPAN͢΀͚ (1) • Go ΅ git repository ΄ URL Ψ೰ਧͭͼαЀφϕЄϸͯΡ

    • CPAN Κ Ruby gems Κ npm ΄Ξ͜΀Ӿ।ᵞ䰱ጱςЄϝЄ͢ ΀͚ • Ӟͺ΄;ͩΣ΁Δ;Δ͹ͼ΀͚΄ͽ͚ͩͩ͜͜;ͭ͵͚ͧͿ ΀΁͚͚͡϶αϣ϶Ϸ΀͚͡΀뺶;റͯ΄͢ࢯ櫞
  11. 21.

    CPAN͢΀͚ (2) • ϶αϣ϶ϷΨറͯ;ͣ΅ • github.com ͽ golang + hogehoge

    ͯΡ • Έ͵ͯΟννΡ • ํ挷ᘏ΁守ͥ • etc…
  12. 25.

    ๔䁭 • ϶αϣ϶Ϸ΄ύγЀϺЄϖ΄ mirror Θ֢౮Ԩਧ;΄ͩ; • ͩ΢΅ Go 1.13 ͽ䌏䖕ͯΡΕ͵͚΀΄ͽ

    2019.8 ΁΅ϷϷЄ φͫ΢Ρ͹Γ͚Ҙ • ֺ͞Ά github.com ៧ͷͼΘ mirror ͡ΟύγЀϺЄϖͽͣΡ Ξ͜΁;͚ͩ͜;Ο͚ͭ
  13. 27.

    $GOPATH ͡Οᭈ΢Ο΢΀͚ (1) • golang ͽ΄樄咲΅ଉ΁ $GOPATH ΄ӥͽᤈ͜஠ᥝ͘͢Ρ • ͘ΟΜΡ϶αϣ϶Ϸ͢

    $GOPATH ΄ӥ΁ᗝ͡΢Ρڹ൉΁΀͹ͼ ͚ͼ͡ͺ $GOPATH ΄ᯈӥͽ樄咲ᤈΥ΀͚;ᶎׯ΀ͩ;΁΀Ρ
  14. 29.

    $GOPATH ͡Οᭈ΢Ο΢΀͚ (3) • Go 1.12 ͽفΡ go mod ͽ

    $GOPATH Ψ䶲΁ͭ΀ͥͼΘΞͥ΀ΡΟ͚ͭ…͢ • ͚ΔΔͽل樄ͫ΢ͼͣ͵͘ΟΜΡϯυϲЄϸ͢ semver ΁䌏䖕ͯΡ஠ᥝ͘͢Ρ • go mod ͽΘϯυϲЄϸ΄κϰϐτϲ΀Ϳ΅ $GOPATH ᯈӥ΁֢Ο΢Ρ΄ͽ ਠق΁䶲΁ͭ΀ͥͼΞͥ΀ΡΥͧͽ΅΀ͫͳ͜ • ͳΘͳΘ $GOPATH ΄ᯈӥͽͰ͹;Κ͹ͼͣ͵͡Ο嬹䙼Ψ䄜͞Ρ΄΅䦒樌͢ ͡͡Πͳ͜ • Go 1.12 ΅ 2019.2 ΁ϷϷЄφԨਧѺҁΘͯͦ͜ͽͯ΃ѺѺ҂
  15. 30.

    ϶αϣ϶Ϸ΄ᓕቘොဩ͢ΖͰ͚ (1) • ϶αϣ϶Ϸ΄αЀφϕЄϸ΅ go get πϫЀϖΨֵ͜ • go get

    -u github.com/motemen/gore ΄Ξ͜΀୵ୗͽׁਂ樛㭚ΘތΗͼαЀφ ϕЄϸͭͼͥ΢Ρ • $GOPATH/src ΁ΘΣΘΣ git clone ͫ΢ͼϠϸϖ͢ᩳΡ • Քࢧ΄ξЄφͶ; $GOPATH/src/github.com/motemen/gore ΀Ϳ • πϫЀϖ϶αЀϑЄϸΘ $GOPATH/bin ΁ϠϸϖͭͼαЀφϕЄϸͭͼͥ΢Ρ • perl ͽ cpanm install Foo::Bar ͯΡ΄;Ͷ͚͵͚Ӟ姼
  16. 31.
  17. 32.

    ϶αϣ϶Ϸ΄ᓕቘොဩ͢ΖͰ͚ (2) • go get ͽαЀφϕЄϸͫ΢Ρ΄΅ git repository ΄ master

    ΄ HEADѺ • 䋚檭΅ go1 ;͚͜ branch or tag ͘͢΢Άͳ΢Ψ憎ΡͧͿΑ Βၺ᭐ͭͼ͚΀͚ཛྷ䯭 • master ͢ stable ͡Ϳ͜͡΅Υ͡ΟΩ΄ͽ΀͡΀͡㷗͚ͭΘ΄ ͘͢Ρ
  18. 33.

    ϶αϣ϶Ϸ΄ᓕቘොဩ͢ΖͰ͚ (3) • go get ͽ΅ version Ψ೰ਧͭͼݐ஑ͯΡͩ;͢ͽͣ΀͚ • ͳΘͳΘ

    version ᓕቘͫ΢ͼ͚ΡϯυϲЄϸ͢੝΀͚ѺѺ • Go 1.12 ͽفΡ go mod ΁ΞΠ semver Ψֵ͜Ξ͜΁΀Ρ΄ ͽϮЀϓͫ΢ͼ͚Ρ϶αϣ϶Ϸ΁΅ၺ᭐ͭͼ͚͹ͼ΅͚Ρ
  19. 34.
  20. 36.

    WebίϤϷξЄτϴЀΨ䨗ͥ;ͣ΄϶αϣ ϶Ϸ΄ᓕቘ (1) • Carton Κ bundler ΄Ξ͜΀̵ϤϺυδμϕᯈӥ΁஠ᥝ΀ϯυϲЄ ϸΨϝЄυϴЀࢴਧͭͼαЀφϕЄϸͯΡ՛奲ΕΨֵͩ͜;͢Α ;ΩͿ

    • go get Ψֵ͜΄΅ᇙਧ΄ϯυϲЄϸ΄䞉㵕Ψ抠Ώ͵͚;̵͡π ϫЀϖֵ͚͵͚;͡͹ͼ䁰ݳ͢Α;ΩͿ • ͭͭ͡ vendoring / glide / dep / vgo / go mod ;͚Σ͚Σ͘͹ͼ 奾ੴͿ΢ֵ͞Ά͚͚΄Ҙ;΀Ρ
  21. 37.

    WebίϤϷξЄτϴЀΨ䨗ͥ;ͣ΄϶αϣ ϶Ϸ΄ᓕቘ (2) • ୮ᶎ΅ glide / dep / go

    mod Ψֵ͚ړͧͼ͚ͥ஠ᥝ͘͢Ρ;௏Υ΢Ρ • glide / dep ΅ֵΥ΢ͼ͚ΡϤϺυδμϕ͢ग̵़ͥΑΒΑΒ๗இ᭗Π΁㵕 ͥ΄ͽ㪥Π䟵͞ΡϯώϦЄτϴЀ֗͢ͳ͜ • vgo ΅ go mod ;ͭͼ Go ΁ݐΠ旿Δ΢͵΄ͽ஫΢ͼᜉ͚ • Go 1.12 ͡Ο΅ go mod Ψֵ͹ͼ͚ͥͩ;΁΀Ρ΅Ͱ • 匍ࣁ΄ Go 1.11 ͽ΅ $GO111MODULE =on ΁ͭͼͥ͠;͠手ͭͽͣΡ
  22. 39.

    ηЄςϷЀνϑЄϸ͢΀͚ (1) • Go ΁΅ηЄςϷЀνϑЄϸ΄䷥ਧᇇ΄Ξ͜΀Θ΄͢΀͚ • Δ͹ͫΟ΀य़ࣈ͡ΟতΗΡͩ;΁΀Ρ • go xxx

    πϫЀϖΨ;΁ͥ͡಑ͺ͡ Makefile Ψ;΁ͥ͡䨗ͥͩ;΁΀Ρ • Ϡϸϖ͢ͳͩΔͽ櫞ͭͥ΀͚΄ͽ̵ͳΩ΀΁ࢯΟ΀͚;͚͞ΆࢯΟ΀͚͢… • ϷϷЄφ䦒΁ tag ಑͹͵Π̵Ϡϸϖͭ͵ϝαϗϷ΁ version ईΗ旿ΩͶΠ΀Ϳਧࣳ ΄㳌ቘ΅ generate ͭ͵͚ཿ • ;ͥ΁ go mod ΁ΞΠ϶αϣ϶Ϸ΄ϝЄυϴЀᓕቘ͢᯿ᥝ΁΀͹ͼ͚ͥ
  23. 40.

    ηЄςϷЀνϑЄϸ͢΀͚ (2) • ౯̸΅ Minilla Κ ExtUtils::MakeMakerҁݘ͚҂ ΁䙼΢ͯͤͼ ͭΔ͹͵ΩΚ… •

    go mod Θֵ͞ΡΞ͜΁΀Ρ̵ͭΒͷΒͷͩ΄旽΄ϑЄϸΘڊ ͼͣͼΘ͚͚殹΀䶲΅ͯΡ
  24. 43.
  25. 44.

    ίυδЀύ • ΀Ͳ Go ͡ • Perl Monger ͢ Golang

    ΨতΗΞ͜͹ͼ䦒΁Ϝϫ͹͵;ͩΣ • Go ΄᥺承՛䯭ͽ਍Ό Perl ;΄ፘ晅ᅩ • Web API Ψ֢͹ͼΕΞ͜ • ϓφϕΨ䨗ͥ • Docker Ϡϸϖͭͼ㵕ͯ͡ • Δ;Η
  26. 45.

    Go ΄᥺承՛䯭ͽ਍Ό Perl ;΄ፘ晅ᅩ • ίυδЀύ (1) • 䄜හ;ࣳ΁ͺ͚ͼ •

    樛හ΁ͺ͚ͼ • ε϶ЄϜЀϖϷЀν΁ͺ͚ͼ • defer ΁ͺ͚ͼ • gorutine ΁ͺ͚ͼ • context.Context ΁ͺ͚ͼ • package ΁ͺ͚ͼ
  27. 46.

    Go ΄᥺承՛䯭ͽ਍Ό Perl ;΄ፘ晅ᅩ • ίυδЀύ (2) • ګக䯤෈΁ͺ͚ͼҁif /

    for / while / switch҂ • goto ΁ͺ͚ͼ • Struct ΁ͺ͚ͼ • interface ΁ͺ͚ͼ • code formatter ΁ͺ͚ͼ • linter ΁ͺ͚ͼ
  28. 48.
  29. 49.
  30. 50.

    樛හ΁ͺ͚ͼ (1) • 樛හ΅ func (୚හ) 䜟Π㮔 { … }

    ;͚͜୵ୗͽ懿ᬿͯΡ • 樛හݷ΅ PascalCase ͽ䨗ͥ; public ;΀Π camelCase ͽ䨗ͥ ; private ΁΀Ρ • ݢ䄜槱୚හΨݑͧ՞ͧΡͩ;ΘͽͣΡ
  31. 51.
  32. 53.
  33. 54.

    樛හ΁ͺ͚ͼ (3) • Perl ͽ΅樛හϷϢήϹЀφΨ䄜හ΁ف΢ͼჁͯͩ;ΘͽͣΡͧ Ϳ go ΅Ϳ͹ͷ͡;͚͜; JavaScript ͹Γ͚ఽͮ

    • ͵Ͷ̵ͭ樛හΨ୚හ΁ͭ͵Π䜟Π㮔΁ͯΡ䁰ݳ΁τνϚώϰЄ Ψق᮱䨗ͥ஠ᥝ͘͢Ρ
  34. 55.

    ε϶ЄϜЀϖϷЀν (1) • go ΅ perl ;ݶͮͽ throw exception Κ

    try / cache ΄Ξ͜΀ֺक़䱛䯤 ͢΀͚ • ֺक़Ψڊͯ䁰ݳ΅ panic() Ψֵ͜ • perl ͽ΅͠΀ͮΕ΄ die ͽͯ΃Ѻ • panic() ΨκϰϐώͯΡ΄΅ defer func () { recover() } Ψֵ͜;ͽͣΡ • perl ͽ΅͠΀ͮΕ΄ eval ͽͯ΃Ѻ
  35. 56.
  36. 58.

    ε϶ЄϜЀϖϷЀν (2) • ᛘ޸ጱ΀ε϶ЄͽϤϺψφΨ奰ԧͭ΀ͧ΢Ά΀Ο΀͚䦒΁ᴴ͹ ͼֵ͜Ώͣ • ͭ͵͢͹ͼ recover() ΄ڊኾΘᛔͰ;Α;ΩͿ΀͚ •

    WebίϤϷξЄτϴЀ΀Ϳͽ΅΂ΡΓΚOutOfIndexጱ΀Θ΄ ͽ϶Ѐόαϭε϶Єͽ panic() ͢咲ኞͯΡݢᚆ௔΅͘Ρ΄ͽϷ μεφϕ΄Ӟኾक़㯎ͽ recover() ͯΡͦΟ͚
  37. 60.
  38. 62.

    defer ΁ͺ͚ͼ (1) • defer func() ͯΡ;匍ࣁ΄樛හ͡Ο䝏ͧΡ䦒΁ func() Ψ䋚ᤈͯΡ •

    Perl ͽ᥺͜ Scope::Guard ΁֒ͼ͚Ρ • go ΄ defer ; Scope::Guard ΄晅͚ • 䜟Π㮔͢΀͚΄ͽ̵Scope::Guard ΄ dismiss ΄Ξ͜΀ͩ;΅ͽͣ΀͚ • φπЄϤΨ䝏ͧ͵䦒ͽ΅΀̵ͥͥ͘ΔͽΘ樛හΨ䝏ͧ͵䦒΁ͭ͡咲㵕ͭ΀͚ • If Κ for ΄Ӿͽ defer Ψ䨗ͥ΄΅఺㾩ͭ͵䞉㵕;΀Ο΀͚ݢᚆ௔͢ṛ͚΄ͽဳ఺
  39. 63.
  40. 65.
  41. 67.

    gorutine ΁ͺ͚ͼ • Go Ψ᨝䖀ͯΡ䱛ᚆ • `go func()` ͯΡͶͧͽ̵㳨φϹϐϖͽ㳌ቘ͢ᩳΡ΄ͽ㪔ڜϤϺ ν϶ϬЀν͢墋㶨΁ͽͣͼͭΔ͜

    • gorutine ݶॊ΄ΚΠ;Π΅ channel Ψֵͩ͜;ͽᤈ͜ • Perl ͽ͚͜ AnyEvent Κ Coro ;༷ஷ΅ΑΒӞ姼ͽͯ΃
  42. 68.

    context.Context ΁ͺ͚ͼ • ᇙਧ΄ gorutine Κ Ӟ昧΄㳌ቘ΄Ӿͽձ఺΄ϔЄόΨف΢ͼ୚ͣࢧͭ͵ Π̵κϰЀψϸ㳌ቘΨူ݊ͫͱΡ͵Η΀Ϳ΁ڥአͯΡ • Perl

    ΄ Amon2 Κ Catalyst (䛖͚ͭ͡) ΀Ϳ΄ $c ;֒͵Ξ͜΀༷ஷ • go ΄䁰ݳ΅ core ΁ف͹ͼ͚Ρ͵Η̵͚Σ͚Σ΀ϯυϲЄϸͽݶͮ API Ψ ڥአͯΡͩ;͢ͽͣΡ΄ͽΗͷΙͥͷΙֵΥ΢ͼ͚Ρ • ᇙ΁WebίϤϷξЄτϴЀΨ֢ΡӤͽ΅ όαϭίγϕΚٖ᮱ε϶Єͽ㳌 ቘΨκϰЀψϸͭ͵͚䦒΀Ϳ΁஠殾΄䱛ᚆͽ;΁ͥ͡୚ͣࢧͯͩ;΁΀Ρ
  43. 69.

    pacakge ΁ͺ͚ͼ (1) • go ͽϯυϲЄϸΨαЀϪЄϕͯΡ䁰ݳ΅ • core ΄䁰ݳ΅ net/http

    ΄Ξ͜΁ͯΡ • ͳ͜ͽ΀͚䁰ݳ΅ github.com/jmoiron/sqlx ΄Ξ͜΁ͯΡ
  44. 70.

    pacakge ΁ͺ͚ͼ (2) • net/http Ψֵ͜䁰ݳ΅ http.Get(“…”) ΄Ξ͜΁ http Ψ

    prefix ; ͭͼֵ͜ • net/http ΨαЀϪЄϕͭͼ͚ΡΞϢήαϸͽΘͭ github.com/ xaicron/http ΄Ξ͜΀ package ΨαЀϪЄϕͭΞ͜;ͯΡ; http ΄ prefix ͢ᤩ͹ͼͭΔ͜ • ͳ΄䁰ݳ΅αЀϪЄϕ;ͣ΁㳨ݷΨͺͧΡͩ;͢ͽͣΡ
  45. 71.
  46. 73.

    pacakge ΁ͺ͚ͼ (4) • Perl ΄䁰ݳ΅ `ϔΰϹμϕϷ::Ϣήαϸݷ` ͢ package ݷͶ͢晅͜

    • Go ΄䁰ݳ΅φπЄϤ΄塅㾨͢ package ΀΄ͽݶͮϔΰϹμϕ Ϸ΁͘Ρ *.go Ϣήαϸ΅قͼݶͮφπЄϤͽ͘Ρ • Perl ΅ϢήαϸφπЄϤ • Go ΄ϊЄφ΅ݶͮϔΰϹμϕϷ΄Ϣήαϸ΁㳌ቘ͢ړවͭͼ ͚Ρ΄͢ฦ᭗
  47. 75.

    ګக䯤෈΁ͺ͚ͼ (1) • If ΁ͺ͚ͼ • if ΁ೡୢ΅஠ᥝ΀ͭ • elseif

    ͽ΅΀ͥ else if • ӣ殻ᄍᓒৼ͢ਂࣁͭ΀͚͵Η̵ͺ΃΁ if ~ else Ψ䨗ͥ஠ᥝ͢ ͘Ρ
  48. 76.

    ګக䯤෈΁ͺ͚ͼ (2) • for ΁ͺ͚ͼ • for ΁Θೡୢ΅஠ᥝ΀ͭ • for

    ΄Ӿͽ΅ break ; continue ֵ͢͞Ρ • foreach 䯤෈΅΀͚͢դΥΠ΁ for … := range var { … } 䯤෈ ֵ͢͞Ρ
  49. 77.
  50. 79.

    switch ΁ͺ͚ͼ • 䘂ݷṛͣ switch ෈ͽ̵ͯ͢go ͽ΅Ξֵ͚ͥΔͯ • case ΄͘;΁

    break Ψ䨗ͥ஠ᥝ͢΀͚΄ͽ఺㾩ͱͰེ΄ case ΁ᤈ͹ͼͭΔ͜;͚͜ϝν᩸ͩ͢Π΁͚ͥ • ེ΄ case ΁ᤈͣ͵͚䁰ݳ΅กᐏጱ΁ fallthrough Ψ䨗ͥ஠ᥝ ͘͢Ρ
  51. 80.
  52. 83.

    interface ΁ͺ͚ͼ • Interface ΁΅伋͵ͯΏͣ樛හ΄ਧ嬝Ψ䨗ͣΔͯ • go ΄ interface ΅

    Java ;晅͹ͼกᐏጱ΁μ϶φҁGo ͽ΅ Struct҂΁奄ͻͣΔͱΩ • Struct ΄ො΁ interface ͢伋͵ͯΏͣϮϊϐϖΨͯΏͼ䋚ᤰͭ͵;ͣ΁̵interfcae Ψ䋚ᤰͭ͵;͚͜ᇫ丆΁΀ΠΔͯ • Interface ΁͘ΔΠ΁Θग़ͥ΄ਧ嬝Ψ䨗͚ͼͭΔ͜;䋚ᤰͯΡ㯎͢य़䄜΀͵Η̵ग़ ͥ΄䁰ݳ interface ΁΅1뺶හ㮆ᑕଶͭ͡䨗͡΢ΔͱΩ • 抍กͭڊͯ;奰ΥΟ΀͚΄ͽ托奞΅፜ͣΔͯ
  53. 84.

    code formatter ΁ͺ͚ͼ (1) • go ΅ϔϢζϸϕͽ go fmt ;͚͜πϫЀϖ͘͢Ρ΄ͽͩ΢Ψֵ

    ͩ͜;ͽπЄϖΨෆ୵ͯΡͩ;͢ͽͣΡ • go ͽ΅ go fmt Ψ᭗ͯͩ;͢୮͵Πڹ΁΀͹ͼ͚Ρ͵Η̵πЄ ϔΰЀνφόαϸ΅قӮኴو᭗ • perl ͽ΅ perltidy Κ App::PRT ΀Ϳ͘͢ΠΔͯ΃Ѻ
  54. 85.

    code formatter ΁ͺ͚ͼ (2) • perl ΄䁰ݳ΅̵parser ΅ C ͽ䨗͡΢ͼ͠Π͡ͺ㵕ጱ΁

    AST Ψ 䯤塈ͯΡ͵Ηᶉጱᥴຉͽ΅ᴴኴ͘͢͹͵ΠͭΔ̵ͯ͢go ͽ΅ ͳΘͳΘπЀϞαϸ᥺承ͽ͘Ρ͵Ηͩ΄旽Π΅䜷͚Κͯͥ΀ͼ ͚Ρ • perl ͽΘ PPI Κ Compiler::LexerΚ Compiler::Parser Ψֵ͞Ά ͡΀Π΄ϹϦϸͽᶉጱᥴຉ΅ݢᚆͽͯ͢ਠኃ΁ΚΡ΄΅΀͡΀ ͡櫞͚ͭͽͯ΃
  55. 86.

    code formatter ΁ͺ͚ͼ (3) • go fmt ΨΘ;΁ͭ͵ go import

    Κ go returns ΀Ϳ΄ϑЄϸΘ ͘Ρ • च๜ጱ΁΅πЄϖ᮱ړ΄ෆ୵΅Ӟ姼ͽ̵import ΄ෆ୵ϸЄϸ ͢ͷΝ͹;晅͹͵Π return ෈Ψ愆ਠͭͼͥ΢͵ΠͯΡ • य़ͣͥ䄜ΥΟ΀͚΄ͽϤϺυδμϕ㶨֖ͽֵ͜Θ΄Ψࢴਧͯ ΢Ά㺔氂΀ͭ
  56. 87.

    linter ΁ͺ͚ͼ • go ΅ᶉጱᥴຉ͢ go ᛔ֛ͽΚΠΚ͚ͯ͵Η̵linter Θ꧌䋚ͭͼ͚Δͯ • 䰤伛πϫЀϖ;ͭͼ͘Ρ

    go vet ΚςЄϖϞЄϓΰ΄ go lint ΅๋֗ᴴֵ͜;͚͚ͽ ͭΝ͜ • go vet ΅πЀϞαϸε϶Є΁΅΀Ο΀͚ͧͿϮϯϷϷЄμ΀ͿͫΔͬΔ΀㺔氂΁΀ Πͳ͜΀πЄϖΨර͞ͼͥ΢Δͯ • go lint ΅ΞΠΞ͚πЄϔΰЀνφόαϸΨ suggest ͭͼͥ΢Δͯ • ͫΟ΁ͣΗ奞͡΀ώδϐμΨᤈ͚͵͚䁰ݳ΅ https://github.com/dominikh/go-tools Ψ手ͯͩ;ΘͽͣΔͯ
  57. 89.
  58. 90.

    ίυδЀύ • ΀Ͳ Go ͡ • Perl Monger ͢ Golang

    ΨতΗΞ͜͹ͼ䦒΁Ϝϫ͹͵;ͩΣ • Go ΄᥺承՛䯭ͽ਍Ό Perl ;΄ፘ晅ᅩ • Web API Ψ֢͹ͼΕΞ͜ • ϓφϕΨ䨗ͥ • Docker Ϡϸϖͭͼ㵕ͯ͡ • Δ;Η
  59. 91.

    Go ͽ๋ṛ΄ Web API Ψ֢͹ͼΕΞ͜Ѻ • ίυδЀύ • WebςЄϝЄΨᒈͼΡ •

    πЄϖ΄䄜ๅ͘͢͹͵Οܨଷ΁ϠϸϖͯΡ • Database ΁ίμψφͯΡ • Web API Ψ䨗͚ͼ͚ͥ
  60. 92.

    WebςЄϝЄΨᒈͼΡ (1) • net/http Ψֵͩ͜;ͽ墋㶨΁ Web ςЄϝЄΨᒈͼΡͩ;͢ͽͣΡ • net/http ΅ςЄϝЄ΁Θμ϶αίЀϕ΁Θ΀Ρṛ䱛ᚆ΀϶αϣ϶ϷЄ

    • ςЄϝЄ΄䁰ݳ΅ٖ᮱ͽ㵛ಋ΁ gorutine Ψኞ౮ͭͼϷμεφϕ͢奰Υ͹͵ ΟᏈ䬤ͭͼͥ΢Ρ΄ͽ΀΁Θᘍ͞Ͱ΁ϷϊЄφΨ㵁ሲጱ΁ֵͩ͜;͢ͽͣΡ • Graceful ShutdownΘ墋㶨΁䋚匍ͽͣΡ΄ͽΞ͚ • HTTP/2 ΁Θ䌏䖕ͭͼ͚Ρ
  61. 94.

    WebςЄϝЄΨᒈͼͼΕΡ (2) • middleware ΁䌏䖕ͭͼΕΡ • Plack ΄ midleware ;ΑΒݶ༷ͮஷ΄Θ΄΀΄ͽ

    Plack Κ͹ ͼ΢Ά䮭㵛ͽͯ • ͚ͺΘ΄όϫϚλ΄ኮ؟Ψ毣΁௏͚ၶ͡ΏͼͥͶ͚ͫ
  62. 96.

    WebςЄϝЄΨᒈͼͼΕΡ (3) • middleware Ψ䨗ͥ;ͣ΄ဳ఺ᅩ • http.responseWriter.WriteHeader() ͭ͵͘;΅ Header Ψ᭄ے

    ͯΡͩ;͢ͽͣ΀͚΄ͽ䶲ΨͺͧΡ஠ᥝ͘͢Ρ • ͵;͞Ά Content-Length Κ X-Frame-Open ΀Ϳ΄ Header Ψ middleware ΄஍㳌ቘͽ᭄ےͯΡͩ;͢ࢯ櫞 • Ε΀ͫΩͿͭ͜ͼΔͯ͡ҘҘ
  63. 97.

    Web ςЄϝЄΨᒈͼΡ (4) • Graceful Shutdown ΁䌏䖕ͯΡ • ςЄϝЄΨෛ͚ͭ gorutine

    ͽ᩸㵕ͭͼ̵main ͽ signal ϕ ϶ϐϤͯΡͩ;ͽ̵ྲ斃ጱ墋㶨΁䋚匍ͽͣΡ
  64. 101.

    䄜ๅ͘͢͹͵Οܨଷ΁ϠϸϖͯΡ (2) • go get github.com/oxequa/realize ͭͼ realize start ͯΡͶͧ

    ͽ *.go Ϣήαϸ΄哶憙Ψͭͼͥ΢Δͯ • 戔ਧϢήαϸ΅ڡࢧ᩸㵕䦒΁ .realize.yaml ΁ͺͥΟ΢Ρ΄ͽ̵ ͘;΅奞ͥ͡抠ෆͭͼ͚ͣΔͭΝ͜
  65. 102.

    Database ΁ίμψφͯΡ (1) • database/sql ΄αЀόЄϢδЄφΨ䋚ᤰͭ͵ driver Ψֵͩ͜; ͽ Database

    ΁ίμψφͽͣΔͯ • Perl ΄ DBI ΄Ξ͜΀Θ΄ͽϔϢήμϕ • Քࢧ΅ github.com/go-sql-driver/mysql Ψֵ͚Δͯ
  66. 103.

    Database ΁ίμψφͯΡ (2) • go-sql-driver-mysql ΅ go ͽقͼ䨗͡΢ͼ͠Π̵libmysqlclient ΁ׁਂͭͼ͚΀͚ •

    ͩ΢΁ΞΠಅ̸ libmysqlclient Ψֵ͹ͼ͚Ρग़ͥ΄᥺承;䞉 㵕͢吖΀Ρ;ͩΣ͘͢ΠΔͯ
  67. 105.

    Database ΁ίμψφͯΡ (4) • πϚμτϴЀΨ揳ΠͯͤͼͭΔ͜㺔氂 • Ϸμεφϕ͢ϝЄφϕͭ͵;ͣ΀Ϳͽ go ΄ concurrency

    ͢䃀य़ͭͼӞ 䶲΁ mysql ΁πϚμτϴЀΨ揳͹ͼͭΔ͚ max_connection ΨηЄϝЄ ͭ͵ΠϷϊЄφΨ͚ᷣͺΌͭͼͭΔ͜ݢᚆ௔͘͢Ρ • Δ͵̵僻洏΁ idel ΄ള姆͢ྜ͹ͼͭΔ͜ • DB.SetMaxIdleConns() ; DB.SetMaxOpenConns() ͽګகͯΡͩ;͢ ͽͣΡͩ͢΄㮔΁΀΁Ψف΢΢Ά͚͚͡΅ίϤϷξЄτϴЀ΄ᥝկེᒫ
  68. 106.

    Database ΁ίμψφͯΡ (5) • wait_timeout ΁୚͹͡͡Ρڹ΁ίϤϷξЄτϴЀ㯎͡ΟπϚμ τϴЀΨᏈ䬤ͭ͵͚ • DB.SetConnMaxLifetime() ͽګகݢᚆ

    • wait_timeout ͭ͵Π֜Ο͡΄ቘኧͽ MySQL ͡ΟπϚμτϴЀ ͢ڔෙͫ΢͵䁰ݳ΅ίϤϷξЄτϴЀ͢ϷμεφϕΨᤈ͹ͼڡ Ηͼړ͡Ρ΄ͽͩͩ΄϶γЀϖϕϷϐϤΨಪ͞Ρ΄΁ํ㵁
  69. 107.

    Database ΁ίμψφͯΡ (6) • Query() Κ Exec() ͽϤϹЄφϨϸύЄΨֵ͹͵䁰ݳ̵Prepare Statement ͢咲ᤈͫ΢ͼͭΔ͜

    • Prepare ΅πϚμτϴЀ㶨֖ͽٖ᮱ጱ΁κϰϐτϲͫ΢Ρ • ͭͭ͡ग़ͥ΄ WebίϤϷξЄτϴЀͽ΅䯭̸΀μεϷЄ͢咲ᤈͫ΢Ρ΄ͽϟϐϕሲ΅͡΀Π͚֗ • Prepare Ψ咲ᤈͱͰ΁ϤϹЄφϨϸύЄΨ go ͽᗝ䟵ͯΡ΄͢অΔ͚ͭ • fmt.Sprintf() Ψֵ͜ොဩ͢ϖκϲϮЀϕͫ΢ͼ͚Ρ̵͢SQL Injection ͢ோ͚ • MySQL ΄䁰ݳ̵Open䦒΄ params ΁ interpolateParams=true ΨͺͧΡͩ;ͽ driver ΄Ӿͽᗝ䟵 Ψͭͼͥ΢Ρ΄ͽμεϷЄ΄咲ᤈහ͢仂Ρ • 托ͭͥ΅ http://dsas.blog.klab.org/archives/52191467.html
  70. 108.

    Database ΁ίμψφͯΡ (7) • 䋚檭΁ϔЄόΨ SELECT ͭͼΕΔͭΝ͜ • 1ϹπЄϖͶͧݐ஑ͭ͵͚䁰ݳ΅ DB.QueryRow(…).Scan(…)

    Ψ ͺ͚͡Δͯ • Scan() ΁΅ϪαЀόЄΨჁͯ஠ᥝ͘͢ΠΔͯ • go ΄୚හ΅㮔Ⴡͭ΀͵Η
  71. 109.
  72. 111.
  73. 112.

    Database ΁ίμψφͯΡ (9) • ϕ϶ЀσμτϴЀΨڥአͭͼ INSERT ͯΡ • ϕ϶ЀσμτϴЀΨڥአͯΡ䁰ݳ΅ DB.Begin()

    Ψ咲ᤈͭͼ Tx Ψݑͧݐ Ρ • ͩ΄ Tx Ψֵ͹ͼ Tx.Exec() Ψᤈͩ͜;ͽϕ϶ЀσμτϴЀ㳌ቘ΁΀Ρ • Tx ͽ΅΀ͥ DB.Exec() ͭ͵䁰ݳ΅ϕ϶ЀσμτϴЀ㳌ቘ΁΀Ο΀͚΄ ͽဳ఺
  74. 113.
  75. 115.

    database/sql ΄϶ϐϞЄΨֵ͜ • github.com/jmoiron/sqlx Ψֵ͜;̵DB.Get() Κ DB.Select() ͽ Struct ΁ϫϐϡЀνͭͼͥ΢Ρ̵ͭrows

    ΄ Close() ΀ͿΘ晒ڔ΁ ᤈ͹ͼͥ΢Ρ • Struct ΁΅όνΨͺ͡͹ͼ `db:”column”` ΀Ϳ;䨗͚ͼ͚ͧΆ䌏䖕 ͭͼͥ΢Ρ • sqlx ΅ database/sql ΄ͯΏͼ΄ل樄樛හΨ䋚ᤰͭͼ͚Ρ΄ͽ̵ QueryRow() ΀ͿΘͳ΄ΔΔֵͩ͜;͢ͽͣΡ
  76. 116.
  77. 117.
  78. 119.

    ϕ϶ЀσμτϴЀ㳌ቘΨ䮭΁ͯΡ • github.com/Code-Hex/sqlx-transactionmanager Ψֵ͜;ϕ϶ЀσμτϴЀ 㳌ቘ͢䮭΁΀ΠΔͯ • Perl ΄ DBIx::TransactionManager ΄Ξ͜΀Θ΄

    • Ϛφϕͭ͵ϕ϶ЀσμτϴЀΨ墋㶨΁䨗ͥͩ;͢ͽͣΡ • sqlx΄϶ϐϞЄ΁΀͹ͼ͚Ρ΄ͽͯΏͼ΄樛හ͢ڥአݢᚆ • ֵ͜䦒΅ tm ϞϐξЄυ΄ϕ϶ЀσμτϴЀϣϺϐμ΄ΕΨڥአͭ͵ො͢Ϝϫ Π΁͚ͥ
  79. 120.
  80. 122.

    μεϷЄϠϸύЄΨֵ͜ • Κ͹·Π IN ܄Ψᛔێͽ䨗ͥ΄΅ᬔ͚Θ΄͘͢Ρ΄ͽμεϷϠϸύЄΨ ֵ͚ΔͭΝ͜ • ᛔړ΅ github.com/Masterminds/squirrel Ψֵ͹ͼ͚Δͯ

    • JOIN ΨތΖͶ͚͵͚΄ξЄφ΄μεϷЄ͢ኞ౮ͽͣΡ΄ͽ׎ڥ • Perl ΄ SQL::Maker ͹Γֵ͚͚ͪͩͷ • لୗϖκϲϮЀϕ΁ςЀϤϸ͢掓੄΀΄ͽֵ͚ො΅ͳͷΟ݇ᆙ΄ͩ;
  81. 124.
  82. 125.
  83. 127.

    Web API Ψ䨗͚ͼ͚ͥ (1) • RESTful ͹Γ͚ JSON Ψᬬͯ API

    Ψ䨗͚ͼ͚ͥ • Twitter͹Γ͚ͷΝ͹;ͭ͵ϮϐψЄυΨಭᑤͽͣΡ API Ψ戔懯ͭΔͯ • POST /users • GET /users/{user_id} • POST /messages • GET /messages/{message_id} • Ε͵͚΀ఽͮ
  84. 128.

    Web API Ψ䨗͚ͼ͚ͥ (1) • ᇙਧ΄ HTTP Method ͡ͺᇙਧ΄ path

    զक़Ύ΄ίμψφ΅ε϶Є΁ͭ ͵͚ • {user_id} ΀ͿΨ͚͚ఽͮ΁઀樄ͭ͵͚ • ;௏͚Δͯ΃ • net/http ኞͽӤ懿Ψ伋͵ͯ΄΅΀͡΀͡ᬔ͚ • HTTPϸЄόЄ΄ github.com/gorilla/mux Ψֵ͚ΔͭΝ͜
  85. 129.
  86. 131.

    negroni Ψֵ͜ • net/http ኞͽ΅ HandlerFunc() ͪ;΁ middleware Ψ晒አͭͼ ͚͡΀ͥͼ΅΀ΟͰय़䄜ΗΩͿ͜΀΄ͽ

    negroni Ψֵ͚Δͯ • negroni Ψֵͩ͜;ͽ̵ᇙਧ΄ path ΁䌏ͭͼͶͧ middleware Ψ晒አͭ͵Π̵愢හ΄ middleware Ψق֛΁晒አͯΡͩ;͢ φϐκϷ;ͧ͡ΡΞ͜΁΀ΠΔͯ
  87. 132.

    Web API ΄䯤౮ (1) • Handler -> Service -> Repository

    ;͚͜Ξ͜΁㳌ቘ͢ၞ΢ΡΞ ͜΁䋚ᤰͭΔͯ • ݱ̸΅ interface ΨՕͭ͵ΚΠݐΠΨᤈ͜ • ͚ͩ͜͜䯤౮Ψ;Ρͩ;ͽݱ䍅ͽ΄䱛ᚆ͢ړ櫝ͫ΢ϓφϕΘ䨗 ͣΚͯͥ΀ΠΔͯ
  88. 133.

    Web API ΄䯤౮ (2) • Handler • HTTP Request Ψݑͧ՞ͧͼϞ϶ϮЄό΄㳌ቘΨᤈ͚

    Service Ψ޷Ήڊͯ • Service ΁ HTTP 樛昧΄Θ΄΅Ⴡͫ΀͚
  89. 135.

    Web API ΄䯤౮ (4) • Repository • ϔЄόϦЄφΚͳ΄՜΄φϕϹЄυΎ΄ίμψφΨ檱ᠰͯΡ Θ΄ •

    愢櫏΅Ϻυϐμ΀Ϳ΅䨗͡΀͚΄͢ቘమ • sqlx.DB ΅ repository ΄ Struct ΄Ӿ΁೮͵ͱΡΞ͜΁ͯΡ
  90. 136.
  91. 137.
  92. 138.
  93. 139.

    ίυδЀύ • ΀Ͳ Go ͡ • Perl Monger ͢ Golang

    ΨতΗΞ͜͹ͼ䦒΁Ϝϫ͹͵;ͩΣ • Go ΄᥺承՛䯭ͽ਍Ό Perl ;΄ፘ晅ᅩ • Web API Ψ֢͹ͼΕΞ͜ • ϓφϕΨ䨗ͥ • Docker Ϡϸϖͭͼ㵕ͯ͡ • Δ;Η
  94. 140.

    ϓφϕΨ䨗ͥ (1) • ϓφϕ΄䨗ͣො • ϓφϕ΅ *_test.go ;͚͜͜ݷڹͽ΄Ϣήαϸ΁䨗ͥ • ֺ͞Ά̵server.go

    Ͷ͹͵Ο server_test.go • testing ϶αϣ϶ϷΨ import ͭͼ func TestXXX(t *testing.T) ͡ΟতΔΡ樛හΨ䨗ͥ
  95. 141.

    ϓφϕΨ䨗ͥ (2) • ϓφϕ΄䋚ᤈ΄՛ො • go test ͽ䋚ᤈͽͣΡ • go

    test ./… ͽٚ䒐ጱ΁ϓφϕͭͼͥ΢Ρ • Perl ΄ prove ΄Ξ͜΀Θ΄
  96. 142.

    Service ΄ϓφϕΨᘍ͞Ρ (1) • ΔͰ Service ΄ϓφϕΨ䨗ͥͩ;Ψᘍ͞Δͯ • Repository ΅

    interface Ψ伋͵ͭͼ͚΢Ά͚͚΄ͽ̵ϓφϕӾ ͽ Struct Ψਧ嬝ͭͼͨ͘΢Ά૧๊ͭ͞Ρͩ;͢ͽ̵ͣService Ͷͧ΁ᵞӾͯΡͩ;͢ͽͣΔͯ
  97. 143.

    Service ΄ϓφϕΨᘍ͞Ρ (2) • ducktyping ͶͧͶ; Service ΄ӾͽͷΙΩ;๗இͭ͵ Repository ΄Ϯ

    ϊϐϖ͢޷Ά΢ͼ͚Ρ͡Υ͡Ο΀͚͡Θͭ΢ΔͱΩ • gomock Ψֵ͜;̵樛හ΄޷Ήڊͭ΄殼ଧΚ޷Ήڊͭࢧහ΀ͿΨϓφϕ ͯΡͩ;͢ͽͣΔͯ • gomock ΅ mockgen ;͚͜πϫЀϖͿψϐϕͽڥአͭΔͯ • mockgen ΁ϯϐμͭ͵͚ go ϢήαϸΨჁͯ; interface Ψ伋͵ͭ͵ go ϢήαϸΨ generate ͭͼͥ΢Δͯ
  98. 144.

    MySQL Ψֵ͹͵ϓφϕ (1) • github.com/lestrrat-go/test-mysqld Ψͺ͜͡ • ΕΩ΀य़অͣ Test::mysqld ΄

    go ϪЄϓΰЀν ͽͯ΃ • test ΄͵Ή΁ਠق΁μϷЄЀ΀ MySQL ΨᒈͷӤͨͼͥ΢ΡΚ ͺ • ΘͷΣΩ MySQL ΄ᒈͷӤͨ΁䦒樌͢͡͡Ρ΄΅᭿ͧΟ΢΀͚
  99. 145.

    MySQL Ψֵ͹͵ϓφϕ (2) • ϓφϕΨṛ᭛΁ࢧͭ͵͚䁰ݳ΅Ԫڹ΁愢හ΄ MySQL Ψ Docker ΀Π MySQL::Sandbox

    ΀ΠͽᒈͷӤͨͼ͚͠ͼࢧͯ΄͢ፘ䄜ΥΟͰ͚͚䶲ͭ͢Δ ͯ • Perl Ͷ;ව̸ͩ΄͘͵Π΅ΚΠੱͥͫ΢ͼ͚ͼᛔړΘค Test::mysqld Ψ࿞ 姆۸ͯΡොဩΚApp::Prove::Plugin::MySQLParallel Ψ䨗͚͵ΠͭͼΔͭ͵ • Test::mysqld::pool ;͡ App::Prove::Plugin::MySQLPool ;͚͡Σ͚Σ͘Ρ • Go ͽ͚͚ఽͮ΁ΚΡොဩ΅Θ͜ͷΝ͚ᎸᑪͭΔͯ
  100. 146.

    WebςЄϝЄ΄ϓφϕ • net/http ΁΅ httptest ;͚͜ WebςЄϝЄϓφϕአ΄϶αϣ϶ ϷЄ͘͢͹ͼͩ΢Ψͺ͜͡;墋㶨΁ϓφϕΨ䨗ͥͩ;͢ͽͣΔͯ • httptest.Server

    Ψֵ͜;䋚檭΁ςЄϝЄΨᒈͷӤͨͼͥ΢Ρ • net.Listen(“tcp”, “127.0.0.1:0”) ;ͥ͡;̵ᑮ͚ͼ͚ΡportΨ Listen ͭͼͥ΢Δͯ • Test::TCP ጱ΀䱛ᚆ͘͢͹ͼ׎ڥͽͯ΃
  101. 147.
  102. 148.

    ίυδЀύ • ΀Ͳ Go ͡ • Perl Monger ͢ Golang

    ΨতΗΞ͜͹ͼ䦒΁Ϝϫ͹͵;ͩΣ • Go ΄᥺承՛䯭ͽ਍Ό Perl ;΄ፘ晅ᅩ • Web API Ψ֢͹ͼΕΞ͜ • ϓφϕΨ䨗ͥ • Docker Ϡϸϖͭͼ㵕ͯ͡ • Δ;Η
  103. 149.

    DockerͽϠϸϖͭͼ㵕ͯ͡ (2) • φϓϐϤ;ͭͼ΅ • golang:latest 厏हͽ go Ψ Linux

    ݻͧ΁Ϡϸϖ • alpine / busybox / scratch ΀Ϳ΄敽ᰁ΀αϮЄυ΁Ϡϸϖͭ ͵ϝαϗϷΨ COPY • ;͚͜ၞ΢ͽͯ
  104. 150.

    DockerͽϠϸϖͭͼ㵕ͯ͡ (2) • net/http ϞϐξЄυΨڥአͭͼ͚Ρ;̵dynamic link ΁΀͹ͼͭΔ̵͚ϝα ϗϷΨπϡЄͭ͵Ͷͧͽ΅㵕͡΀͚ • `go

    build -a -tags netgo -installsuffix netgo` ΀Ϳ;ͭͼϠϸϖͯΡͩ;ͽ static link ΁΀͹ͼͥ΢Δͯ • ׁਂͭͼ͚Ρ϶αϣ϶Ϸͽ cgo Ψֵ͹ͼ͚Ρ䁰ݳ΅ͳ΢Θ dynamik link ΁ ΀Ρ΄ͽզӥ΄Ξ͜΁ͭΔͯ • `go build -a -tags netgo -installsuffix netgo --ldflags '-extldflags "-static"'`
  105. 151.

    DockerͽϠϸϖͭͼ㵕ͯ͡ (3) • WebςЄϝЄ΅ net/http Ψֵͩ͜;͢Α;ΩͿ΀΄ͽ dynamic link ΁΀͹ͼͭΔ͜΄΅ϜϫΠ͢ͷ •

    ̵ͭͭ͡golang:latest ͽͳ΄ΔΔ docker build ͭͼͭΔ͜; πЀϓϗ͢ 700MB ᑕଶ΁΀͹ͼͭΔ͜΄ͽ̵හMB͡Οහ܈ MBᑕଶ΄ੜͫ΀ Linux ΨڥአͯΡͩ;Ψ͠㵣ΗͭΔͯ
  106. 152.
  107. 153.

    ίυδЀύ • ΀Ͳ Go ͡ • Perl Monger ͢ Golang

    ΨতΗΞ͜͹ͼ䦒΁Ϝϫ͹͵;ͩΣ • Go ΄᥺承՛䯭ͽ਍Ό Perl ;΄ፘ晅ᅩ • Web API Ψ֢͹ͼΕΞ͜ • ϓφϕΨ䨗ͥ • Docker Ϡϸϖͭͼ㵕ͯ͡ • Δ;Η
  108. 154.

    Δ;Η • Perl ͽङ͹͵Ꭳ挷Ψͺ͡͹ͼ Go ͽ WebςЄϝЄΨ䨗͚ͼ͚ͥ ොဩ΁ͺ͚ͼ扖ͭΔͭ͵ • ᛔړᛔ᫝ΔͶ娞ଶ͚֗͢΄ͽ୚ͣ姆ͣ毇䔴͹ͼ͚ͣ͵͚ͽͯ

    • Perl ֵ͹ͼ͚͵Ո͢奾䯤 Go Ψֵ͹ͼ͚Ρ΄ͽ̵Ϳͩ͡ͽΕ͵ Ξ͜΀϶αϣ϶Ϸ͘͢͹͵Πͭͼ΀ΩͶ͚͚͡ͽͯ΃
  109. 155.