Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

ݚम֓ཁ w 🚩ୡ੒໨ඪ w ॻ੶΍ϦϑΝϨϯεΛಡΈͳ͕ΒϥΠϒϥϦΛ׆༻͠ ͨ(PϓϩάϥϜΛॻ͚Δ͜ͱ w ଞਓͷॻ͍ͨ(PίʔυΛϨϏϡʔͰ͖Δ͜ͱ w 🚩ཤम৚݅ w $΍1ZUIPOͳͲͷԿΒ͔ͷϓϩάϥϛϯάݴޠΛϚ ελʔ͍ͯ͠Δ͜ͱ

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

࣮ࢪҊ಺ w ݚमεέδϡʔϧ͸ো֐ରԠͳͲͰٸᬎϦεέ δϡʔϧ͢ΔՄೳੑ͕͋Γ·͢ w ࠔͬͨ͜ͱ͕͋Ε͹ࣾ಺4MBDLͷHPQIFST νϟϯωϧͰ૬ஊ͍ͯͩ͘͠͞ w શͯͷճʹࢀՃ͞Εͨํʹ͸ɺݚमऴྃޙʹम ྃূॻΛൃߦ͠·͢

Slide 5

Slide 5 text

ࢀߟॻ w ϓϩάϥϛϯάݴޠ(P ؙળग़൛ Ξϥ ϯɾυϊόϯ ϒϥΠΞϯɾΧʔχϋϯஶࣲా ๕थ༁ Λ༻͍·͢ w ݚमࢀՃ࣌ʹ͸ɺ͓खݩʹ͝༻ҙ͘ ͍ͩ͞ w ݚम಺Ͱ͸ຊจʹ͸৮Εͣɺίʔυ ྫ΍࿅श໰୊Λར༻͠·͢

Slide 6

Slide 6 text

ຊ೔ͷΰʔϧ w 🚩ΰʔϧ w (Pͷઃܭࢥ૝ɾύϥμΠϜΛཧղ͢Δ w (Pͷಘҙͳ͜ͱɺۤखͳ͜ͱΛ೺Ѳ͢Δ w (PͷฒߦॲཧϓϩάϥϛϯάͷϞσϧͱಛੑΛ஌Δ w ❌ΰʔϧͰ͸ͳ͍ w (PͰϓϩάϥϛϯά͕Ͱ͖ΔΑ͏ʹͳΔ

Slide 7

Slide 7 text

(Pͷઃܭࢥ૝ ެࣜϚείοτ (PQIFS ˠ

Slide 8

Slide 8 text

(Pݴޠͱ͸ (P͸Φʔϓϯιʔεͷϓϩάϥϛϯάݴޠ 
 Ͱ͋Γɺ؆ܿͰ৴པੑ͕ߴ͘ɺޮ཰తͳ 
 ιϑτ΢ΣΞͷߏஙΛ༰қʹ͠·͢ɻ HPMBOHPSHΑΓ package main import "fmt" func main() { fmt.Println("Hello, world!") } $ go build hello.go $ ./hello Hello, world! $ $ go run hello.go Hello, world! $ ιʔείʔυ ίϯύΠϧ࣮ߦ ίʔυΛ࣮ߦ ✔︎ $ϥΠΫͳೃછΈ΍͍͢ߏจ ✔︎ ߦ຤ηϛίϩϯෆཁ ✔︎ Πϯσϯτ͸λϒʹ౷Ұ

Slide 9

Slide 9 text

ಈ͔ͯ͠ΈΑ͏ 👉IUUQTQMBZHPMBOHPSH

Slide 10

Slide 10 text

1MBZHSPVOEͷิ଍ w <4IBSF>ϘλϯΛԡͤ͹ɺॻ͍ͨίʔυΛଞͷਓͱڞ༗ Ͱ͖ΔϦϯΫ͕ੜ੒͞Ε·͢ w ϦϯΫྫIUUQTQMBZHPMBOHPSHQ5L,6K;&5"RJ w ୭΋͕ಉ͡ग़ྗ݁ՌΛಘΒΕΔΑ͏ɺ࣌ࠁ͸ৗʹ 65$ʹݻఆ͞Ε͍ͯ·͢ w ࣮ߦ࣌ؒͱ$16ɺϝϞϦͷ࢖༻ྔʹ͸੍ݶ͕͋Γ·͢ w ֎෦ͷωοτϫʔΫΞΫηε͸Ͱ͖·ͤΜ

Slide 11

Slide 11 text

ஶ໊ͳ࠾༻ϓϩδΣΫτ Ϋϥ΢υΠϯϑϥ ؂ࢹɾσʔλॲཧ ϢʔςΟϦςΟ

Slide 12

Slide 12 text

(PΛઃܭͨ͠ਓ w ͦ΋ͦ΋ઃܭͨ͠ͷ୭Α

Slide 13

Slide 13 text

(PΛઃܭͨ͠ਓ w ,FO5IPNQTPO🇺🇸 w %FOOJT3JUDIJF ͱڞʹ 
 $ݴޠͱ6OJYΛ։ൃͨ͠ਓ w ਖ਼نදݱɺ65'ͳͲ΋։ൃ w νϡʔϦϯά৆ ೥ w ݱ৬(PPHMF ʙ

Slide 14

Slide 14 text

(PΛઃܭͨ͠ਓ w 3PC1JLF🇨🇦 w 6OJY։ൃऀͷҰਓ w 65'։ൃऀͷҰਓ w ໊ஶʮϓϩάϥϛϯά࡞๏ʯڞஶऀ 
 
 w ݱ৬(PPHMF ࿨༁ ઈ൛ ৽૷൛

Slide 15

Slide 15 text

(PΛઃܭͨ͠ਓ w 3PCFSU(SJFTFNFS🇨🇭 w +BWB)PU4QPU7.։ൃऀͷҰਓ w 7+4&OHJOF։ൃऀͷҰਓ 
 
 w ݱ৬(PPHMF

Slide 16

Slide 16 text

(Pͷىݯ w (P͕ड͚ܧ͍ͩͭͷ ྲྀΕ w $ݴޠجຊߏจͳͲ w .PEVMB0CFSPO 
 Ϟδϡʔϧɾύο έʔδͷ֓೦ͳͲ w $41ฒߦੑͷ֓೦ ϓϩάϥϛϯάݴޠ(P1YJW ·͕͖͑ ΑΓ

Slide 17

Slide 17 text

٬؍తʹݟΔͱʜ 1SPHSBNNJOH MBOHVBHF 5ZQFTZTUFN (FOFSJDT .PEVMFT ($ 4ZOUBY .FUBQSPHSBN NJOH &YFDVUJPO /JN 4UBUJDBOE TUSPOH :FT :FT :FT NVMUJQMF BOEPQUJPOBM 1ZUIPOMJLF :FT $PNQJMFE CJOBSZ $ 4UBUJDBOE XFBL /P /P /P $ 7FSZMJNJUFE $PNQJMFE CJOBSZ $ 4UBUJDBOE XFBL :FT /P /P $MJLF -JNJUFE $PNQJMFE CJOBSZ % 4UBUJDBOE TUSPOH :FT :FT :FT PQUJPOBM $MJLF :FT $PNQJMFE CJOBSZ (P 4UBUJDBOE TUSPOH /P :FT :FT $MJLF /P $PNQJMFE CJOBSZ 3VTU 4UBUJDBOE TUSPOH :FT :FT /P $MJLF -JNJUFE $PNQJMFE CJOBSZ +BWB 4UBUJDBOE TUSPOH :FT :FT :FT NVMUJQMF $MJLF /P &YFDVUFEWJB UIF+7. 1ZUIPO %ZOBNJDBOE TUSPOH /" :FT :FT 1ZUIPO :FT &YFDVUFEWJBUIF 1ZUIPOJOUFSQSFUFS -VB %ZOBNJDBOE XFBL /" :FT :FT .PEVMBMJLF :FTWJB .FUBMVB &YFDVUFEWJBUIF -VBJOUFSQSFUFSPS -VB+*5DPNQJMFS /JNJO"DUJPO1ΑΓ ٭஫লུ

Slide 18

Slide 18 text

੩తɾڧ͍ܕ෇͚ w ੩తܕ෇͚ίϯύΠϧ࣌ʹશͯͷม਺ͷܕ͕֬ఆ͍ͯ͠Δ w ڧ͍ܕ෇͚ίϯύΠϥ͕ܕͷ҆શੑΛݫີʹݕࠪ͢Δ w ܕਪ࿦ม਺એݴ࣌ʹ͢Ͱʹܕ͕෼͔͍ͬͯΕ͹ܕ໊ΛলུՄ package main import "fmt" func main() { var n int var s string n = 10 s = "foo" var m = n + 1 fmt.Printf("%d %d %s\n", n, m, s) // Output: 10 11 foo } package main import "fmt" func main() { n := 10 // লུม਺એݴ s := "foo" // ʏ m := n + 1 // ʏ fmt.Printf("%d %d %s\n", n, m, s) // Output: 10 11 foo }

Slide 19

Slide 19 text

δΣωϦΫεʜͳ͍ w (Pʹ͸ܕ҆શͳ൚༻ԽΛࢧԉ͢Δ࢓૊Έ͕ͳ͍ w (PͰ௥Ճ͞ΕͨಉظԽ.BQ͸ɺѻ͏ܕ͸શۭͯΠϯλ ϑΣʔεܕ ԿͰ΋ೖΔܕ ɺऔΓग़࣌͠ʹܕΩϟετ͕ඞཁʜ // standard map var m = make(map[string]string) m["foo"] = "bar" value, _ := m["foo"] m["foo"] = value + "2" δΣωϦοΫ͸ศརͰ͸͋Γ·͕͢ɺܕγεςϜͱϥϯλΠϜʹෳࡶ͞ʹΑΔίε τΛ΋ͨΒ͠·͢ɻզʑ͸ɺ͜ͷෳࡶ͞ʹݟ߹͏͚ͩͷՁ஋Λ࣋ͭઃܭͷΞΠσΞ Λ·ͩݟ͚ͭΔ͜ͱ͕Ͱ͖͍ͯ·ͤΜ͕ɺ͜Ε͔Β΋ܧଓͯ͠ߟ͍͖͑ͯ·͢ɻ HPMBOHPSHͷ'"2ʹΑΔͱʜ // sync map var m sync.Map m.Store("foo", "bar") value, _ := m.Load("foo") m.Store("foo", value.(string)+"2") (P 
 Ͱ࠾༻ͷݟࠐʂ

Slide 20

Slide 20 text

ΦϒδΣΫτࢦ޲ w :&4͚ͩͲɾɾɾ w Ϋϥε͕ͳ͍ɺΫϥε֊૚΋ͳ͍ w ܧঝ͸ෆՄɺίϯϙδγϣϯͷΈରԠ w ΠϯλϑΣʔε͸ඞཁͳϝιουΛ͍࣋ͬͯΔ͔Ͳ͏ ͔Ͱ҉໧తʹຬ଍͞ΕΔ w ϝϯόʔ໊ͷઌ಄͕େจࣈͳΒެ։ QVCMJD ɺ 
 খจࣈͳΒඇެ։ QBDLBHFQSJWBUF

Slide 21

Slide 21 text

Ϋϥε͕ͳ͍ type Animal struct { Name string Birth time.Time } func (a Animal) Age() int { // Method return int(time.Since(a.Birth).Hours() / 24 / 365) } type Cattle struct { Animal // Embed ID int64 } ͋Δͷ͸ߏ଄ମͱϝιου ϨγʔόʔΛ΋ͭؔ਺ ͚ͩ ߏ଄ମͷຒΊࠐΈͰίϯϙδγϣϯΛ࣮ݱ ஫Ӟ೥Λແࢹ

Slide 22

Slide 22 text

ΠϯλϑΣʔε͸͋Δ type Caller interface { Call() string } type Cattle struct { ID string } func (c Cattle) Call() string { return "moo" } func main() { var caller Caller caller = Cattle{ID: "123"} fmt.Println(caller.Call()) // moo } ΠϯλϑΣʔεͰఆٛͨ͠ϝιουͱಉ͡γάχνϟͷϝιο υ͕ἧ͍ͬͯΕ͹୅ೖͰ͖Δ limplementsͱ͔͍Βͳ͍ 👍

Slide 23

Slide 23 text

Τϥʔॲཧ w ؔ਺͸ଟ஋ΛฦͤΔͷͰɺ໭Γ஋ʹerrorܕΛఴ͑ɺ࢖͍ख͸nil͔Λ൑ఆ͢Δ w ਖ਼௚͠ΜͲ͍͕ɺݩདྷΤϥʔϋϯυϦϯά͸ϓϩάϥϚͷ੹೚ɺؤڧʹ࡞Δบ͕ͭ͘ w ॲཧΛଧͪ੾Δpanic()ͱ͍͏ػߏ΋͋Δ͕ɺจࣈ௨Γக໋తͳ৔߹ʹͷΈ࢖͏ func fetch(url string) ([]byte, error) { resp, err := http.Get(url) if err != nil { return nil, fmt.Errorf("failed to communicate: %v", err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("failed to get: HTTP %s", resp.Status) } body, err := ioutil.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("failed to read: %v", err) } return body, nil } ߦதߦ͕Τϥʔॲཧʂ

Slide 24

Slide 24 text

ςετ func Sum(list []int) int { sum := 0 for _, i := range list { sum += i } return sum } type sumTest struct { in []int out int } var sumTests = []sumTest{ {[]int{1, 2, 3}, 6}, {[]int{}, 0}, {[]int{-1, 1}, 1}, // Θ͟ͱ FAIL } func TestSum(t *testing.T) { for i, test := range sumTests { out := Sum(test.in) if out != test.out { t.Errorf("#%d Sum(%v) = %d, want %d", i, test.in, out, test.out) } } } w ςετίʔυͷϑΝΠϧ໊͸ 
 
 xxx_test.go YYY͸೚ҙ w ςετؔ਺໊͸TestͰ࢝·Γ 
 
 Ҿ਺ʹ͸*testing.TΛड͚ Δ w ཧ૝͸package΋ݩίʔυͱ 
 
 ෼཭͢Δ _testΛ͚ͭΔ

Slide 25

Slide 25 text

ςετ $ go test -v -cover sum* === RUN TestSum --- FAIL: TestSum (0.00s) sum_test.go:20: #2 Sum([-1 1]) = 0, want 1 FAIL coverage: 100.0% of statements FAIL command-line-arguments 0.012s w ༷ʑͳςετ͕࣮ߦՄೳ w DPWFSͰΧόϨοδܭଌ ্ه w SBDFͰϨʔείϯσΟγϣϯݕ஌༗ޮԽ w CFODIͱUFTUJOH#ͰϕϯνϚʔΫ࣮ߦ w ظ଴݁ՌΛίϝϯτͰॻ͍ͯςετ͢Δ͜ͱ΋Ͱ͖Δ &YBNQMFTػೳ

Slide 26

Slide 26 text

ͦͷଞ͋Δ΋ͷͳ͍΋ͷ w ࡾ߲ԋࢉࢠ͸ͳ͍if-elseͪΌΜͱॻ͘ w while/doจ͸ͳ͍ϧʔϓ͸forͷΈ ແݶϧʔϓ͸for {} w map/filter/reduce/…͸ͳ͍δΣωϦΫεͳ͠Ͱ͸ʜ w ϥϜμࣜ͸ͳ͍ؔ਺ϦςϥϧͰಗ໊ؔ਺͸࡞ΕΔ w assert %C$ ͸ͳ͍खൈ͖Τϥʔॲཧ͢Δਓ͕ଟ͍͔Β w assertXX()౳ͷςετϔϧύʔ͸ͳ͍ૉ௚ʹجຊߏจͰ w ϙΠϯλ͸͋Δͨͩ͠ϙΠϯλԋࢉ͸ͤ͞ͳ͍Αʂ

Slide 27

Slide 27 text

(Pʹ͓͚Δฒߦॲཧ

Slide 28

Slide 28 text

ฒߦॲཧ w (PͰฒߦॲཧΛ ߦ͏ʹ͸ʜ func f1() { fmt.Println("f1") } func f2() { fmt.Println("f2") } func main() { go f1() go f2() time.Sleep(100 * time.Microsecond) } +VTUlgoz $ go run main.go f1 f2 $ go run main.go f2 f1

Slide 29

Slide 29 text

ฒߦॲཧ w νϟωϧΛ࢖͏ͱɺฒߦ ॲཧؒͰ஋΍ϝοηʔδ Λ΍ΓͱΓͰ͖Δ w ૹ৴จch <- x w ड৴จx = <-ch w ଴͚ͭͩͳΒ<-ch func f1(done chan bool) { fmt.Println("f1") done <- true } func f2(done chan bool) { fmt.Println("f2") done <- true } func main() { done1 := make(chan bool) done2 := make(chan bool) go f1(done1) go f2(done2) <-done1 <-done2 }

Slide 30

Slide 30 text

ฒߦॲཧ w ଟॏԽෳ਺ͷ νϟωϧΛ଴ͪड ͚ɺ 
 ࠷ॳʹड৴ͨ͠΋ ͷΛर͏ func f1(done chan bool) { fmt.Println("f1") done <- true } func f2(done chan bool) { fmt.Println("f2") done <- true } func main() { done1 := make(chan bool) done2 := make(chan bool) go f1(done1) go f2(done2) select { case <-done1: fmt.Println("f1 is first!") case <-done2: fmt.Println(“f2 is first!") } } $ go run main.go f1 f1 is first! f2 
 $ go run main.go f2 f2 is first!

Slide 31

Slide 31 text

ฒߦॲཧ w νϟωϧʹ͸஋ΛૹΓଓ͚Δ͜ͱ͕Ͱ͖Δ w ૊ΈࠐΈؔ਺close()ͰνϟωϧͷऴྃΛ଴ͪखʹ఻͑ΒΕΔ func async(counter chan int) { for i := 1; i <= 3; i++ { counter <- i time.Sleep(100 * time.Microsecond) } close(counter) } func main() { counter := make(chan int) go async(counter) for count := range counter { fmt.Println(count) } } $ go run main.go 1 2 3 $

Slide 32

Slide 32 text

ฒߦॲཧ w όοϑΝαΠζΛࢦఆ͢ΔͱόοϑΝ͋ΓνϟωϧʹͳΔ w ड৴ʹରͯ͠ૹ৴͕ͷ৔߹͕Ӭԕʹૹ৴଴ͪʹͳΔͷΛ๷͛Δ func f1(done chan bool) { fmt.Println("f1") done <- true } func f2(done chan bool) { fmt.Println("f2") done <- true } func main() { done := make(chan bool, 2) go f1(done) go f2(done) <-done } $ go run main.go f2 $ go run main.go f2 f1

Slide 33

Slide 33 text

ฒߦॲཧͷཪଆ 1SPDFTT 1SPDFTT 1SPDFTT 5ISFBE 5ISFBE 5ISFBE $16 $16 ࣮ߦ ࣮ߦ εέδϡʔϦϯά 
 ίϯςΩετεΠον

Slide 34

Slide 34 text

ฒߦॲཧͷཪଆ 1SPDFTT 5ISFBE 5ISFBE $16 $16 ࣮ߦ NBJO 
 HPSPVUJOF HPSPVUJOF HPSPVUJOF ʜ ࣮ߦ ࣮ߦ ࣮ߦ ࣮ߦ ࣮ߦ ࣮ߦ 04εέδϡʔϥʔ HPϥϯλΠϜ 
 ./εέδϡʔϥʔ ʜ

Slide 35

Slide 35 text

ฒߦॲཧͷཪଆ w HPSPVUJOF͸ͱͯ΋ܰྔʂখ͞ͳؔ਺ͷ࣮ߦͰ΋͡ΌΜ͡ΌΜ্ཱͪ͛ͯ΋ ߏΘͳ͍ w ଞͷݴޠͷίϧʔνϯͱ͸ҟͳΓɺϓϩάϥϚ͕தஅ΍࠶։Λࢦࣔ͢Δ͜ͱ ͸Ͱ͖ͳ͍ ࣮ߦ୯Ґ ؅ཧ ࠷খελοΫ 
 αΠζ -JOVY ϓϦΤϯϓγϣϯ 1SPDFTT 04 .# ͋Γ 5ISFBE 04 .# ͋Γ HPSPVUJOF (Pϓϩηε ,# ϒϩοΫ͍ͯ͠Δ HPSPVUJOFͷΈ

Slide 36

Slide 36 text

(PMBOH +BWB 1ZUIPO (PMBOH +BWB 1ZUIPO HPSPVUJOFͷҖྗ w େྔͷ.255௨৴Λߦ͏ϓϩάϥϜͰϦιʔεফඅΛൺֱ w ௨৴਺Λ૿΍ͯ͠΋ϝϞϦফඅͷ૿Ճ͕গͳ͘ɺͳ͓͔ͭ଎͍ʂ ϝϞϦফඅྔ # ফඅ࣌ؒ T ݕূίʔυIUUQTHJUIVCDPNNJLBONRUUCFODINBSLT

Slide 37

Slide 37 text

ฒߦॲཧͷཪଆ w (0."9130$4؀ڥม਺ w σϑΥϧτ஋ϥϯλΠϜͷ$16ίΞ਺ w ڝ߹ঢ়ଶ͕ͳ͍͔ςετΛ͢Δͱ͖ͱ͔ʹΘ͟ͱ૿΍͢ func main() { for { go fmt.Print(0) fmt.Print(1) } } (0."9130$4HPSVONBJOHP (0."9130$4HPSVONBJOHP

Slide 38

Slide 38 text

·ͱΊ

Slide 39

Slide 39 text

(Pݴޠ͸ʜ ✔︎ ίϯϐϡʔλΛ஌Γਚͨ͘͠ઋਓୡ͕γϯϓϧ ͞Λॏࢹ͢Δ఩ֶΛकΓൈ͍ͯ࡞Γ্͛ͨݴޠ ✔︎ $ϥΠΫͳฏқͳߏจͱɺແବΛ࡟͗མͱͨ͠ ΦϒδΣΫτࢦ޲Λαϙʔτ ✔︎ ϚϧνίΞ࣌୅ʹదԠ͠͏ΔɺฒߦॲཧΛε Ϛʔτʹ࣮ݱͰ͖ΔಠࣗͷϞσϧͱϥϯλΠϜΛ ࣋ͭ

Slide 40

Slide 40 text

࣍ճ༧ࠂ w ࣍ճ͸ʮ؀ڥߏஙͱ(JU (JU)VCͷجຊʯͰ͢ w ·ͩ(JU)VCΞΧ΢ϯτΛਃ੥͍ͯ͠ͳ͍ํ ͸ɺҊ಺ʹ͕ͨͬͯ͠༻ҙͷ্ɺਃ੥γεςϜ ʹ௨͍ͯͩ͘͠͞ w ෼͔Βͳ͔ͬͨͱ͜Ζ΍࣭໰ͳͲ͸ɺࣾ಺ 4MBDLHPQIFSTνϟϯωϧʹ౤ߘ͍ͩ͘͞