Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

˞ લճͷ13ͷ 
 ղઆλΠϜ

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

ຊ೔ͷΰʔϧ w 🚩ΰʔϧ w (Pͷ๛෋ͳඪ४ϥΠϒϥϦΛ၆ᛌ͢Δ w Α͘࢖͏ϥΠϒϥϦΛ࣮ࡍʹ࢖ͬͯΈΔ w ❌ΰʔϧͰ͸ͳ͍ w શͯͷඪ४ϥΠϒϥϦΛ࢖͑ΔΑ͏ʹͳΔ

Slide 5

Slide 5 text

ඪ४ϥΠϒϥϦͷ 
 า͖ํ

Slide 6

Slide 6 text

τοϓϨϕϧͷҰཡ BSDIJWF DSZQUP fl BH JP QMVHJO TZOD CV fi P EBUBCBTF GNU MPH SF fl FDU TZTDBMM CVJMUJO EFCVH HP NBUI SFHFYQ UFTUJOH CZUFT FNCFE IBTI NJNF SVOUJNF UFYU DPNQSFTT FODPEJOH IUNM OFU TPSU UJNF DPOUBJOFS FSSPST JNBHF PT TUSDPOW VOJDPEF DPOUFYU FYQWBS JOEFY QBUI TUSJOHT VOTBGF (PͰ௥Ճ (PͰ௥Ճ (PͰ௥Ճ

Slide 7

Slide 7 text

ࣾ಺ίʔυͷར༻࣮੷ BSDIJWF DSZQUP fl BH JP QMVHJO TZOD CV fi P EBUBCBTF GNU MPH SF fl FDU TZTDBMM CVJMUJO EFCVH HP NBUI SFHFYQ UFTUJOH CZUFT FNCFE IBTI NJNF SVOUJNF UFYU DPNQSFTT FODPEJOH IUNM OFU TPSU UJNF DPOUBJOFS FSSPST JNBHF PT TUSDPOW VOJDPEF DPOUFYU FYQWBS JOEFY QBUI TUSJOHT VOTBGF (JU)VCͷίʔυݕࡧͰௐ΂·ͨ͠

Slide 8

Slide 8 text

ଟ਺ͷαϒσΟϨΫτϦ w BSDIJWFUBSBSDIJWF[JQ w DPNQSFTTC[JQDPNQSFTT fl BUFDPNQSFTTH[JQ DPNQSFTTM[XDPNQSFTT[MJC w DPOUBJOFSIFBQDPOUBJOFSMJTUDPOUBJOFSSJOH w DSZQUPBFTDSZQUPDJQIFSDSZQUPEFTDSZQUPETBDSZQUP FDETBDSZQUPFEDSZQUPFMJQUJD 
 ʜ εϥογϡͰ۠੾ΒΕͨΑΓࡉ͔͍෼ྨ͕͋Δ΋ͷ͕ଟ͍

Slide 9

Slide 9 text

า͖ํ w QLHHPEFW΢ΣϒαΠτ w ϒϥ΢βͰશମΛ၆ᛌ͠ͳ͕Β୳͍ͨ͠ͱ͖ w HPEPDίϚϯυ w ࢖͏ύοέʔδ͸ܾ·͍ͬͯΔͱ͖ w (JU)VCͷίʔυ w ୯ʹϥΠϒϥϦΛ࢖͏Ҏ্ͷ৘ใΛಘ͍ͨͱ͖

Slide 10

Slide 10 text

QLHHPEFW΢ΣϒαΠτ 👉IUUQTQLHHPEFWTUE

Slide 11

Slide 11 text

HPEPDίϚϯυ FODPEJOHDTWΛௐ΂͍ͨͳˠgo doc csv ·ͣ͸/FX8SJUFSؔ਺͔ͳʜˠgo doc csv.NewWriter ͭ͗ʹ8SJUFSߏ଄ମΛৄ͘͠ʜˠgo doc csv.Writer 'MVTIϝιουͷ࢓༷͸ʜˠgo doc csv.Writer.Flush go doc go doc [. ] go doc [.][. ] go doc [.][.]

Slide 12

Slide 12 text

(JU)VCͷίʔυ w (Pͷίʔυ͸(JU)VCͰ ΋ ެ։͞Ε͍ͯΔ 
 IUUQTHJUIVCDPNHPMBOHHP w ඪ४ϥΠϒϥϦ͕͋Δͷ͸TSDҎԼ 
 IUUQTHJUIVCDPNHPMBOHHPUSFFNBTUFS TSD w ඪ४ϥΠϒϥϦͷઃܭ΍࣮૷͸ྑ͍͓खຊɺؔ਺ͷ ໋໊ύλʔϯ͔ΒυΩϡϝϯτͷॻ͖ํ·Ͱɺਅࣅ Ͱ͖ΔϙΠϯτ͸ͨ͘͞Μ͋Δ

Slide 13

Slide 13 text

ඪ४ϥΠϒϥϦ 
 ࣮ફϋϯζΦϯ

Slide 14

Slide 14 text

45&1 fl BH package mai n import ( "flag " "fmt " ) func main() { areaCode := flag.String("c", "130000", "ΤϦΞίʔυ" ) flag.Parse( ) fmt.Printf("ΤϦΞίʔυ͸ %s Ͱ͢\n", *areaCode ) } fl BHίϚϯυϥΠϯҾ਺Λศརʹѻ͏ϥΠϒϥϦ 👇ࣸܦͯ͠ΈΑ͏ EBZIBOETPONBJOHP ʮgo run .ʯʮgo run . -c 016000ʯʮgo run . -hʯͷ࣮ߦ݁Ռ͸ʁ

Slide 15

Slide 15 text

45&1OFUIUUQ resp, err := http.Get("https://www.jma.go.jp" + "/bosai/forecast/data/overview_forecast/" + *areaCode + ".json" ) if err != nil { fmt.Println(err ) os.Exit(1 ) } defer resp.Body.Close( ) fmt.Printf("εςʔλείʔυ͸ %d Ͱ͢\n", resp.StatusCode) OFUIUUQଟ࠼ͳ)551௨৴͕ՄೳͳϥΠϒϥϦ 
 ·ͣ͸࠷΋؆୯ʹ࢖͑Δ(FU Λ࢖ͬͯΈΔ 👇NBJOؔ਺ͷ຤ඌʹॻ͖଍ͯ͠ΈΑ͏ ʮgo run .ʯ͸ɺʮgo run . -c 123ʯ͸ʹͳΕ͹0,

Slide 16

Slide 16 text

45&1JP body, err := io.ReadAll(resp.Body ) if err != nil { fmt.Println(err ) os.Exit(1 ) } fmt.Println(string(body)) JPศརͳ൚༻ೖग़ྗॲཧϥΠϒϥϦ 👇NBJOؔ਺ͷ຤ඌʹॻ͖଍ͯ͠ΈΑ͏ ʮgo run .ʯͷ࣮ߦ݁Ռ͸ʁ

Slide 17

Slide 17 text

45&1MPH if err != nil { log.Fatalf("઀ଓͰ͖·ͤΜͰͨ͠: %v", err ) } MPHγϯϓϧͳϩάग़ྗϥΠϒϥϦ if err != nil { fmt.Println(err ) os.Exit(1 ) } 👇ҎԼͷΑ͏ʹॻ͍͍ͯͨͱ͜ΖΛʜ 👇ҎԼͷΑ͏ʹॻ͖׵͑ͯΈ·͠ΐ͏ if err != nil { log.Fatalf("Ϩεϙϯεͷड৴ʹࣦഊ͠·ͨ͠: %v", err ) }

Slide 18

Slide 18 text

45&1FODPEJOHKTPO if resp.StatusCode != http.StatusOK { log.Fatalf("HTTP %s: %v", resp.Status, string(body) ) } forecast := struct { HeadlineText string `json:"headlineText" ` Text string `json:"text" ` }{ } if err := json.Unmarshal(body, &forecast); err != nil { log.Fatalf("JSON ͷղੳʹࣦഊ͠·ͨ͠: %v", err ) } log.Println("ʲϔουϥΠϯʳ" + forecast.HeadlineText ) log.Println("ʲຊจʳ" + forecast.Text) FODPEJOHKTPO+40/ύʔαʔˍσίʔμʔ 👇NBJOؔ਺ͷ຤ඌʹॻ͖଍ͯ͠ΈΑ͏ ʮgo run .ʯʮgo run . -c 016000ʯͷ࣮ߦ݁Ռ͸ʁ

Slide 19

Slide 19 text

45&1UJNF ReportDatetime time.Time `json:"reportDatetime"` UJNF೔෇΍࣌ࠁΛѻ͏ͱ͖ʹඞཁʹͳΔϥΠϒϥϦ 
 ॻࣜͷࢦఆ͕ಠಛʜ 👇GPSFDBTUͷߏ଄ମʹϑΟʔϧυΛ଍ͯ͠ΈΑ͏ log.Println("ʲใࠂ࣌ࠁʳ" + forecast.ReportDatetime.Format("2006೥01݄02೔ 15࣌04෼")) 👇NBJOؔ਺ͷ຤ඌʹॻ͖଍ͯ͠ΈΑ͏ ʮgo run .ʯʮgo run . -c 016000ʯͷ࣮ߦ݁Ռ͸ʁ

Slide 20

Slide 20 text

ίʔυྫͷඋߟ w ࠓճར༻ͨ͠ؾ৅ிͷ63-͸ެࣜͷ"1*Ͱ͸ͳ͘࢓༷ͷܧଓੑ͸อূ͞Ε ͍ͯ·ͤΜ͕ɺ੓෎ඪ४ར༻ن໿ͷԼͰར༻Ͱ͖·͢ 
 ࢀߟIUUQTUXJUUFSDPNF@UPZPEBTUBUVT T w ΤϦΞίʔυ͸ɺҎԼͷϖʔδΛ։͍ͯௐ΂͍ͨ஍఺Λબ୒ޙɺϒϥ΢βʹ දࣔ͞Εͨ63-ͷBSFB@DPEFͱ͍͏ΫΤϦύϥϝʔλ͔Β࠾औͰ͖·͢ 
 👉IUUQTXXXKNBHPKQCPTBJGPSFDBTU w SFTQ#PEZ$MPTF ͸ࣦഊ࣌FSSPSܕ͕ฦ٫͞ΕΔͷͰɺ͜ΕΛर͏ʹ͸ ҎԼͷΑ͏ʹॻ͖·͢ 
 defer func() {
 if err := resp.Body.Close(); err != nil {
 log.Printf(“ೖྗετϦʔϜͷΫϩʔζʹࣦഊ͠·ͨ͠: %v", err)
 }
 }()

Slide 21

Slide 21 text

ޙͷճͰ঺հ͢Δ΋ͷ w OFUIUUQͷαʔόʔػೳͱIUNMUFNQMBUF͸ ୈճͰઆ໌༧ఆ w TZODύοέʔδ͸ୈճͰઆ໌༧ఆ w UFTUJOHύοέʔδ͸ୈճͰઆ໌༧ఆ w EBUBCBTFύοέʔδ͸ୈճͰઆ໌༧ఆ

Slide 22

Slide 22 text

࠷ۙͷΞοϓσʔτ

Slide 23

Slide 23 text

DPOUFYUͷొ৔ (P͔ΒDPOUFYUϥΠϒϥϦ͕ొ৔ 
 λΠϜΞ΢τॲཧͳͲͷѻ͍͕ΑΓ໌շʹ url := flag.String("u", "https://www.desamis.co.jp/", "URL" ) timeout := flag.Duration("t", 500 * time.Millisecond, "઀ଓλΠϜΞ΢τ" ) flag.Parse( ) ctx, _ := context.WithTimeout(context.Background(), *timeout ) req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil ) if err != nil { panic(err ) } resp, err := new(http.Client).Do(req) // ࢦఆͨ͠λΠϜΞ΢τظؒΛ௒͑Δͱࣦഊ͢Δ σϑΥϧτಈ࡞ʹ೚ͤΔͱ͖͸ context.Background() Λ࢖͏
 ઃܭ్தͩͬͨΓͰఆ·Βͳ͍࣌༻ʹ context.TODO() ΋͋Δ 👇

Slide 24

Slide 24 text

FNCFEͷొ৔ (P͔ΒFNCFEϥΠϒϥϦ͕ొ৔ 
 ࣮ߦόΠφϦ FYF ʹϑΝΠϧΛαΫοͱຒΊࠐΈʂ package mai n import ( _ "embed " "fmt " ) //go:embed memo.jso n var memo []byt e func main() { fmt.Println(string(memo) ) } package mai n import ( "embed " "fmt " ) //go:embed publi c var public embed.F S func main() { memo, _ := public.ReadFile("public/memo.json" ) fmt.Println(string(memo) ) } ϑΝΠϧΛຒΊࠐΉ σΟϨΫτϦΛ·Δ͝ͱຒΊࠐΉ

Slide 25

Slide 25 text

JPJPVUJMͷ࣮࣭ഇࢭ (P͔ΒJPJPVUJMͷػೳ͕PTͱJPʹҠ২ 
 ࠓޙ͸ޓ׵ੑͷͨΊʹ࢒͞ΕΔ͚ͩͱͳΔ #FGPSF "GUFS ioutil.Discard io.Discard ioutil.NopCloser io.NopCloser ioutil.ReadAll io.ReadAll ioutil.ReadDir os.ReadDir ioutil.ReadFile os.ReadFile ioutil.TempDir os.MkdirTemp ioutil.TempFile os.CreateTemp ioutil.WriteFile os.WriteFile

Slide 26

Slide 26 text

࿅श

Slide 27

Slide 27 text

࿅श໰୊ w ࿅श໰୊ 1 <ϑΥϧμ໊EBZFY> w ·ͣ͸1ͷGFUDIͷࣸܦ͔Β w ࿅श໰୊ 1 <ϑΥϧμ໊EBZFY> w ͖͞΄ͲͷϋϯζΦϯͰطʹ௨ͬͨಓͳͷͰ ؆୯Ͱ͢Ͷ

Slide 28

Slide 28 text

ʙղઆλΠϜʙ

Slide 29

Slide 29 text

͕࣌ؒ༨ͬͨΒʜ w ࿅श໰୊ 1 <ϑΥϧμ໊EBZ FY> w ·ͣ͸11ͷHJUIVCΛEBZHJUIVC ϑΥϧμʹ࣮૷ɺ࣍ʹ11ͷJTTVFT ΛEBZFYϑΥϧμʹ࣮૷͔ͯ͠Βணख w ࿅श໰୊ 1 <ϑΥϧμ໊EBZFY> w ·ͣ͸11ͷMJTTBKPVTͷࣸܦ͔Β

Slide 30

Slide 30 text

ίʔυΛॻ͖ऴ͑ͨΒ w ʮϢʔβʔ໊QSBDUJDFʯϒϥϯνͰ࡞ۀ͍ͯ͠Δ͜ͱΛ֬ೝ͍ͯͩ͘͠͞ w 74ίʔυͷҰ൪ࠨԼʹදࣔ͞Ε͍ͯ·͢ w มߋΛεςʔδ͠ɺίϛοτ͍ͯͩ͘͠͞ w 74ίʔυͷࠨϝχϡʔͷʮιʔε؅ཧʯ͔Βૢ࡞ w ίʔυΛ(JU)VCʹϓογϡ͍ͯͩ͘͠͞ w 74ίʔυͷҰ൪ࠨԼͷϒϥϯν໊ͷ͙͢ӈʹ͋ΔΞΠίϯ͔Βૢ࡞ ্ਤ w ϓϧϦΫΤετΛ࡞੒͍ͯͩ͘͠͞ w ʮιʔε؅ཧʯͷ্෦ʹΞΠίϯ͕͋Γ·͢

Slide 31

Slide 31 text

࣍ճ༧ࠂ w ࣍ճ͸ 
 ʮϞδϡʔϧγεςϜͱ֎෦ϥΠϒϥϦʯͰ͢ w ෼͔Βͳ͔ͬͨͱ͜Ζ΍࣭໰ͳͲ͸ɺࣾ಺ 4MBDLHPQIFSTνϟϯωϧʹ౤ߘ͍ͩ͘͞ w ຊ೔ͷ಺༰ΛΑΓਂ͘ཧղ͍ͨ͠ํ͸ɺεϥΠ υ QLHHPEFW΢ΣϒαΠτ ΛಡΜͰΈͯ ͍ͩ͘͞