Slide 1

Slide 1 text

(Pݚमୈظ %": :VUBLB,BUP 
 3% %&4".*4 %&4".*4ࣾ಺ݚम

Slide 2

Slide 2 text

ݚमܭը ճ ೔࣍ ༧ఆ λΠτϧ ୈճ Ր (Pͷجຊ ୈճ Ր ؀ڥߏஙͱ(JU (JU)VCͷجຊ ୈճ Ր جຊߏจ ୈճ Ր ߏ଄ମɺεϥΠεɺϚοϓ ୈճ Ր ඪ४ϥΠϒϥϦ͸΍Ί͙Γ ୈճ Ր ϞδϡʔϧγεςϜͱ֎෦ϥΠϒϥϦ ୈճ Ր )FSPLV(Pೖ໳ ୈճ Ր "84-BNCEB(Pೖ໳ ୈճ Ր ฒߦॲཧϓϩάϥϛϯά ୈճ Ր ୯ମςετٕ๏ ୈճ Ր σʔλϕʔεΞΫηε ୈճ Ր 'ZOFʹΑΔ(6*ΞϓϦέʔγϣϯ։ൃ ୈճ Ր ࣾ಺(PϓϩδΣΫτͷίʔυղઆ

Slide 3

Slide 3 text

˞ લճͷ13ͷ 
 ղઆλΠϜ

Slide 4

Slide 4 text

ຊ೔ͷΰʔϧ w 🚩ΰʔϧ w (Pͷ)551αʔόʔ։ൃํ๏Λཧղ͢Δ w )FSPLVͱ(Pͷ૬ੑͷྑ͞Λମײ͢Δ w ❌ΰʔϧͰ͸ͳ͍ w ϑϧελοΫ΍ϚΠΫϩαʔϏε։ൃΛ໨ࢦ͢

Slide 5

Slide 5 text

)FSPLV

Slide 6

Slide 6 text

)FSPLVͱ͸ w ೥ʹ3VCZPO3BJMT੡8FCΞϓϦͷϗε ςΟϯάαʔϏεͱͯ͠ొ৔ w ೥ʹ4BMFTGPSDF͕ങऩɺσʔλ࿈ܞػೳ΋ w ݱࡏ͸༷ʑͳݴޠɾϑϨʔϜϫʔΫʹରԠ

Slide 7

Slide 7 text

)FSPLVͷ࢓૊Έ ιʔείʔυ #VJMEQBDLT 4MVH Ϗϧυ 
 4MVH$PNQJMF %ZOPT σϓϩΠ 
 ϦϦʔε 
 ࣮ߦ )FSPLVϓϥοτϑΥʔϜ )FSPLV3PVUFS 8FCτϥϑΟοΫ "EEPOT

Slide 8

Slide 8 text

ྉۚମܥ 1MBO $16 ϝϞϦ උߟ ݄EZOP 'SFF W$16 .# ෼ΞΫηε 
 ͳ͠ͰεϦʔϓ )PCCZ W$16 .# 5FBNTͰ 
 બ΂Δ࠷খαΠζ 4UBOEBSEY W$16 .# &OUFSQSJTFͰ 
 બ΂Δ࠷খαΠζ 4UBOEBSEY W$16 (# 1FSGPSNBODF. ઐ༗ (# 1FSGPSNBODF- ઐ༗ (# ৄࡉ͸IUUQTXXXIFSPLVDPNEZOPT

Slide 9

Slide 9 text

(Pͱͷ૬ੑ w )FSPLVͷ࠷খϓϥϯ͸ϝϞϦ͕গͳ্͍εέʔϧΞοϓ͸ߴՁ w ϝϞϦ࢖༻ޮ཰͕ߴ͍(P͸࠷খίετͷ··େ͖ͳ࢓ࣄ͕Ͱ͖Δ w Ϗϧυ࣌ؒ ෼ ɺ4MVHαΠζ .# ͳͲͷ੍໿͕͋Δ w ίϯύΠϧ͕ߴ଎Ͱ࣮ߦόΠφϦ͸ແବ͕࡟͗མͱ͞ΕΔ(P͸ 
 ֤छ੍໿Λड͚ʹ͍͘ w શͯͷ)FSPLVͷϓϩηε͸೔ճ࠶ىಈ $ZDMJOH ͕͔͔Δ w %ZOP࣌ʹ͸μ΢ϯλΠϜ͕ൃੜ͢Δ͕ɺ(PͳΒىಈ͕ߴ଎ͳ ͷͰ$ZDMJOHͷӨڹΛ࠷খݶʹͰ͖Δ

Slide 10

Slide 10 text

)FSPLV։ൃͷᎄ w 5IF5XFMWF'BDUPS"QQ"EBN8JHHJOT )FSPLV ։ൃऀ ͕ఏএͨ͠Ϟμϯ8FCΞϓϦ։ൃͷํ๏࿦ w จࣈ௨Γ߲໨͔ΒͳΔ ίʔυϕʔε ґଘؔ܎ ઃఆ όοΫΤϯυαʔϏε ϏϧυɺϦϦʔεɺ࣮ߦ ϓϩηε ϙʔτόΠϯσΟϯά ฒߦੑ ഇغ༰қੑ ։ൃຊ൪Ұக ϩά ؅ཧϓϩηε 👉IUUQTGBDUPSOFUKB

Slide 11

Slide 11 text

ϋϯζΦϯ

Slide 12

Slide 12 text

ϋϯζΦϯͷྲྀΕ (JU)VCͰϦϙδτϦΛ࡞Δ 74$PEFͰίʔυΛ࣮૷͢Δ (JU)VCʹϓογϡ͢Δ )FSPLV"QQΛ࡞੒͢Δ σϓϩΠ͢Δ

Slide 13

Slide 13 text

45&1ϦϙδτϦͷ࡞੒ IUUQTHJUIVCDPNOFX 
 ʹΞΫηε͠ɺҎԼΛೖྗ 0XOFS ࣗ෼ͷΞΧ΢ϯτ 3FQPTJUPSZ/BNF IFSPLVHPUPPMCPY %FTDSJQUJPO ྫ )FSPLV(PͰ࡞ͬͨಓ۩ശ 1VCMJD1SJWBUF 1VCMJD˞ "EEB3&"%.& fi MF ☑ νΣοΫ "EEHJUJHOPSF ☑UFNQMBUF(P $IPPTFBMJDFOTF ೚ҙ ˞ߨࢣʹΑΔϑΥϩʔΛԁ׈ʹ͢ΔͨΊͰ͋Γɺٕज़తͳ੍໿Ͱ͸͋Γ·ͤΜ

Slide 14

Slide 14 text

45&1ϦϙδτϦͷෳ੡ 74$PEFΛ։͖ʮΑ͏ͦ͜ʯը໘Λදࣔͤ͞·͢ 
 ϝχϡʔͷ<ϔϧϓ><Α͏ͦ͜>Ͱݺͼग़͠Մೳ ʮ(JUϦϙδτϦͷΫϩʔϯʜʯΛΫϦοΫ͠·͢ ೖྗ૭ʹ͋Δʮ(JU)VC͔Βෳ੡ʯΛબ୒͠·͢ ʮ(JU)VCϢʔβʔIFSPLVHPUPPMCPYʯͱλΠϓ͠ɺબ୒͠·͢ ʮϗʔϜσΟϨΫτϦTSDHJUIVCDPN(JU)VCϢʔβʔʯͷϑΥϧμʹೖ Γ·͢ (JU)VCϢʔβʔͷͱ͜Ζ͸ઌि࡞ͬͨ͸ͣͰ͢ ʮϦϙδτϦͷ৔ॴΛબ୒ʯϘλϯΛΫϦοΫ͠·͢ μΠΞϩά͕ग़ΔͷͰʮ։͘ʯϘλϯΛΫϦοΫ͠·͢

Slide 15

Slide 15 text

45&1HPNPEJOJU ద౰ͳϑΝΠϧ 3&"%.&NEͳͲ ΛӈΫ ϦοΫͯ͠ʮ౷߹λʔϛφϧΛ։͘ʯΛબ୒͠ ·͢ ʮHPNPEJOJUʯʻ&OUFSʼΛೖྗ͠·͢ ΤΫεϓϩʔϥʔ͔Βʮ৽͍͠ϑΝΠϧʯΞΠ ίϯΛΫϦοΫ͠ʮNBJOHPʯΛ࡞੒͠·͢

Slide 16

Slide 16 text

45&1NBJOHP package mai n // import লུ.. . func handleHome(w http.ResponseWriter, r *http.Request) { log.Printf("%s %s", r.Method, r.RequestURI ) w.Write([]byte("͜Μʹͪ͸ʂ") ) } func main() { port := os.Getenv("PORT") // ࣮ߦ࣌ʹ Heroku ͕ࢦఆ͢Δϙʔτ൪߸Λऔಘ if len(port) == 0 { port = "8080" // ϩʔΧϧͰ࣮ߦ͢Δͱ͖ͷϙʔτ൪߸Λࢦఆ } http.HandleFunc("/", handleHome ) log.Printf("ϙʔτ %s Ͱ଴ͪड͚Λ։࢝͠·͢...", port ) if err := http.ListenAndServe(":"+port, nil); err != nil { log.Printf("αʔόʔ͕ҟৗऴྃ͠·ͨ͠: %v", err ) } }

Slide 17

Slide 17 text

45&1खݩͰςετ w ౷߹λʔϛφϧͰʮHPSVOʯʻ&OUFSʼ w ϒϥ΢βͰIUUQMPDBMIPTUʹΞΫηε w ϒϥ΢βͷදࣔͱλʔϛφϧͷϩάΛ֬ೝ͠·͢ ϙʔτ 8080 Ͱ଴ͪड͚Λ։࢝͠·͢.. . GET / GET /favicon.ico ֬ೝͨ͠Β$USM$Ͱऴྃ

Slide 18

Slide 18 text

45&1(JU)VC΁൓ө 74$PEFͷιʔε؅ཧλϒͰશͯͷมߋΛε ςʔδ͠ίϛοτ͠·͢ ϝοηʔδ͸ద౰ ը໘ࠨԼͷϒϥϯν໊ͷӈʹ͋Δมߋͷಉظද ͔ࣔΒϓογϡ͠·͢

Slide 19

Slide 19 text

45&1μογϡϘʔυ IUUQTEBTICPBSEIFSPLVDPNʹΞΫηε͠ɺϩάΠϯ͠·͢ w ΞΧ΢ϯτ࡞੒͕·ͩͷํ͸IUUQTTJHOVQIFSPLVDPN͔Β࡞੒͍ͯͩ͘͠͞ ը໘ࠨ্ͷνʔϜબ୒͕l1FSTPOBMzʹͳ͍ͬͯΔ͜ͱΛ֬ೝ͠· ͢ ͳ͍ͬͯͳ͚Ε͹มߋ ը໘ӈ্ͷϘλϯ͔Β<$SFBUFOFXBQQ>Λબ୒͠·͢

Slide 20

Slide 20 text

45&1"QQ࡞੒ ར༻Մೳͳద౰ͳ "QQ໊Λ୳ͯ͠ೖ ྗ͠·͢ 
 ྫ(JU)VCϢʔ βʔUPPMCPY <$SFBUFBQQ>Ϙλ ϯΛΫϦοΫ͠·͢

Slide 21

Slide 21 text

45&1(JU)VCͱ઀ଓ %FQMPZNFOUNFUIPEͰ l(JU)VCzΛબ୒͠·͢ ϦϙδτϦ໊Λೖྗ͠ <4FBSDI>ΛΫϦοΫ͠·͢ ϦϙδτϦ͕දࣔ͞ΕΔͷ Ͱ<$POOFDU>ΛΫϦοΫ͠ ·͢ 1 2 3

Slide 22

Slide 22 text

45&1खಈσϓϩΠ (JU)VCͱͷ઀ଓΛऴ͑ͨΒɺ Ұ൪Լ·ͰεΫϩʔϧ͠ <%FQMPZ#SBODI>ΛΫϦοΫ ͠·͢ ͠͹Β͘଴ͭͱϩά͕ྲྀΕ l:PVSBQQXBTTVDDFTTGVMMZ EFQMPZFEzͱදࣔ͞ΕΔ͸ͣ Ͱ͢ <7JFX>ϘλϯΛΫϦοΫ͠· ͢

Slide 23

Slide 23 text

ͻΈͭͷϖʔδ

Slide 24

Slide 24 text

#BTJDೝূͱ͸ w खͬऔΓૣ͘ϖʔδʹΞΫηε੍ݶ͍ͨ͠ͱ͖ʹ࢖Θ ΕΔ w ύεϫʔυ͕ฏจͰྲྀΕΔͨΊɺ)5514Ҏ֎Ͱ͸࢖ ͏ͷ͸ඇৗʹةݥ

Slide 25

Slide 25 text

௥Ճͯ͠ΈΑ͏ func handleSecret(w http.ResponseWriter, r *http.Request) { user, password, _ := r.BasicAuth( ) if user != "user" || password != "password" { w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"` ) http.Error(w, "ೝূʹࣦഊ͠·ͨ͠", http.StatusUnauthorized ) retur n } log.Printf("%s %s", r.Method, r.RequestURI ) w.Write([]byte("ൿີͷϖʔδͰ͢ʂ") ) } http.HandleFunc("/", handleHome) http.HandleFunc("/secret", handleSecret) // ௥Ճ log.Printf("ϙʔτ %s Ͱ଴ͪड͚Λ։࢝͠·͢...", port) NBJOHPͷNBJO ͷதʹ௥Ճ NBJOHP಺ʹ௥Ճ

Slide 26

Slide 26 text

ಈ࡞֬ೝ λʔϛφϧͰʮHPSVOʯʻ&OUFSʼͰαʔόʔΛ࠶ͼىಈ͠ɺ ϒϥ΢βͰIUUQMPDBMIPTUTFDSFUʹΞΫηε͠·͢ ೝূμΠΞϩά͕ग़Δ͸ͣͳͷͰɺΘ͟ͱؒҧͬͨϢʔβʔ໊ ΍ύεϫʔυΛೖΕͯΈͯΤϥʔʹͳΔ͜ͱΛ֬ೝ͠·͢ ࠷ޙʹਖ਼͍͠Ϣʔβʔ໊ͱύεϫʔυͰʮൿີͷϖʔδͰ ͢ʂʯ͕දࣔ͞ΕΔ͜ͱΛ֬ೝ͠·͢

Slide 27

Slide 27 text

IUNMUFNQMBUF

Slide 28

Slide 28 text

IUNMUFNQMBUFͱ͸ w ඪ४ϥΠϒϥϦͷ)5.-ςϯϓϨʔτΤϯδϯ w ଞʹ͸൚༻ͷUFYUUFNQMBUF͕͋Δ ϝʔϧૹ৴ͳͲͰ໾ཱͭ w γϯϓϧͳ͕ΒॊೈͰڧྗͳػೳΛ࣋ͭ

ࠓ೔ͷఱؾ͸{{.Weather}}Ͱ͢ɻ

࠷ߴؾԹ͸{{printf "%.1f" .Temp}}℃Ͱ͢ɻ

{{if eq .Weather "੖"} }

෍ஂΛׯ͠·͠ΐ͏ɻ

{{end}} ࣜͷॻ͖ํ͸ϙʔϥϯυه๏ 1PMJTI/PUBUJPO

Slide 29

Slide 29 text

ςϯϓϨʔτͷར༻ UFNQMBUFσΟϨΫτϦΛ࡞੒ɺͦͷதʹ JOEFYHPIUNMΛ࡞੒͠·͢ ҎԼͷίʔυΛೖྗ͠·͢ ಓ۩ശ

Α͏ͦ͜ {{.UserName}} ͞Μʂ

ݱࡏ࣌ࠁ͸ {{.Time.Format "2006/1/2 15:04:05"}} Ͱ͢ɻ

Slide 30

Slide 30 text

ͪͳΈʹ w (PςϯϓϨʔτʹ͸ެࣜͷ֦ுࢠ͕ͳ͍͕ɺ HPIUNM͸(P-BOE౳ͷ*%&͕ඪ४Ͱೝࣝ͢Δ w 74$PEFͰHPIUNMͷߏจϋΠϥΠτΛ͢Δʹ ͸֦ுػೳʮHPUFNQMBUFTZOUBYʯ͕͓͢͢Ί

Slide 31

Slide 31 text

ύʔεͱ࣮ߦ t := template.Must(template.ParseFiles("template/index.gohtml") ) if err := t.Execute(w, struct { UserName strin g Time time.Tim e } { “ήετ" , time.Now() , }); err != nil { log.Printf("ςϯϓϨʔτ %s ͷ࣮ߦʹࣦഊʂ: %v", t.Name(), err ) http.Error(w, "಺෦ΤϥʔͰ͢", http.StatusInternalServerError ) } IBOEMF)PNF ಺Λ࡟আ͠ɺҎԼΛೖྗ ࠶౓αʔόʔΛىಈ͢Δͱʜ

Slide 32

Slide 32 text

ςϯϓϨʔτͷ෦඼Խ {{define "menu"} } Men u {{end}} UFNQMBUF@NFOVHPIUNM˞Λ࡞੒͠ɺҎԼΛೖྗ UFNQMBUFJOEFYHPIUNMͷCPEZͷԼ͋ͨΓʹҎԼΛ௥Ճ {{template "menu"}} IBOEMF)PNF ಺ͷUFNQMBUF1BSTF'JMFT ݺͼग़͠ΛҎԼͷΑ͏ʹมߋ template.ParseFiles("template/index.gohtml", "template/_menu.gohtml") ˞ʮ@ʯ͸෦඼Ͱ͋Δ͜ͱΛ໊લͰڧௐ͍͚ͨͩ͠

Slide 33

Slide 33 text

ςϯϓϨʔτͷ෦඼Խ αʔόʔΛىಈ͠ͳ͓ͯ͠ϒϥ΢βͰ࠶౓ΞΫηε͢Δͱɺ͜͏ͳΔ͸ͣʂ

Slide 34

Slide 34 text

5*14

Slide 35

Slide 35 text

ศརϥΠϒϥϦɾ'8 w 0"VUIΫϥΠΞϯτΛ࣮૷͍ͨ͠ 
 ˠHPMBOHPSHYPBVUI͕͓͢͢Ί w VTFSTJEΈ͍ͨͳύεύϥϝʔλʔΛड͚͍ͨ 
 ˠHJUIVCDPNHPSJMMBNVY͕͓͢͢Ί w ͍ΘΏΔϑϨʔϜϫʔΫͳͲ 
 ˠHJO CFFHP FDIP HPB౳ଟ਺͋Δ͕ɺ·ͣ͸ ඪ४ϥΠϒϥϦΛ͔ͬ͠Γ࢖͍͜ͳ͢ͷ͕Α͍

Slide 36

Slide 36 text

ͳ'SFF%ZOP w ·ͣ͸ΫϨδοτΧʔυΛొ࿥ͯ͠ʮೝূࡁΈΞΧ΢ϯτʯʹ ͢Δ w ݄͋ͨΓͷແྉ࿮͕͔࣌ؒΒ ࣌ؒʹͳΔ w )FSPLV"EEPOT͕ར༻ՄೳʹͳΔ w )FSPLV4DIFEVMFS"EEPOΛΞϓϦʹ௥ՃɺʮDVSM IUUQTΞϓϦ໊IFSPLVBQQDPNʯίϚϯυΛఆظ࣮ߦ ͤ͞Δ w 6QUJNF3PCPU΍/FX3FMJD4ZOUIFUJDTͳͲͰ΋Α͍

Slide 37

Slide 37 text

࿅श

Slide 38

Slide 38 text

࿅श՝୊ w ࿅श՝୊ w ৽͍͠ϖʔδΛ௥Ճ͍ͯͩ͘͠͞ 
 63-ɺϑΝΠϧ໊ɺ಺༰౳͸શͯࣗ༝ w ࿅श՝୊ w )FSPLVΞϓϦʹ؀ڥม਺ $PO fi H7BST Λઃఆ͢ Δํ๏Λௐ΂ɺ#BTJDೝূͷϢʔβʔ໊ͱύεϫʔυ Λ؀ڥม਺͔ΒಡΉΑ͏ʹมߋ͍ͯͩ͘͠͞ 
 ઃఆ஋͸ଞͷαʔϏε౳Ͱ࢖͍ͬͯͳ͍΋ͷʹ͍ͯͩ͘͠͞

Slide 39

Slide 39 text

ίʔυΛॻ͖ऴ͑ͨΒ w มߋΛεςʔδ͠ɺίϛοτ͍ͯͩ͘͠͞ w 74$PEFͷࠨϝχϡʔͷʮιʔε؅ཧʯ͔Βૢ࡞ w ίʔυΛ(JU)VCʹϓογϡ͍ͯͩ͘͠͞ w 74$PEFͷҰ൪ࠨԼͷϒϥϯν໊ͷ͙͢ӈʹ͋ΔΞΠίϯ͔ Βૢ࡞ w )FSPLVʹσϓϩΠ͍ͯͩ͘͠͞ ࣗಈσϓϩΠΛߏ੒ͯ͠΋ྑ͍ w ࣾ಺4MBDLHPQIFSTʹ)FSPLVΞϓϦͷ63-ΛషΓ෇͚ͯ൸ ࿐͍ͯͩ͘͠͞

Slide 40

Slide 40 text

࣍ճ༧ࠂ w ࣍ճ͸ʮ"84-BNCEB(Pೖ໳ʯͰ͢ w ෼͔Βͳ͔ͬͨͱ͜Ζ΍࣭໰ͳͲ͸ɺࣾ಺ 4MBDLHPQIFSTνϟϯωϧʹ౤ߘ͍ͩ͘͞ w ຊ೔ͷ಺༰ΛΑΓਂ͘ཧղ͍ͨ͠ํ͸ɺ )FSPLV%FW$FOUFSͷ֤υΩϡϝϯτΛಡΜͰ Έ͍ͯͩ͘͞ 
 IUUQTEFWDFOUFSIFSPLVDPNKBDBUFHPSJFTHPTVQQPSU