Slide 1

Slide 1 text

at Student Go #1 ΍͸ΓԶͷ Go ΞϓϦέʔγϣϯઃܭ͸
 ·͕͍ͪͬͯΔɻ

Slide 2

Slide 2 text

LUS !LUS@!LUS 6OJWFSTJUZPG"J[V XIPBNJ

Slide 3

Slide 3 text

w (Pͷࢥ૝ͱඪ४ύοέʔδͷಛ௃ w (PΞϓϦέʔγϣϯͷઃܭ ࠓ೔͓࿩͢Δ͜ͱ

Slide 4

Slide 4 text

w Զͷߟ͑ͨ࠷ڧͷΞʔΩςΫνϟ w ΞϓϦέʔγϣϯ֎෦ͷ͜ͱ %#ɺ8FCαʔόɺ FUD ࠓ೔͓࿩͠ͳ͍͜ͱ

Slide 5

Slide 5 text

w ͳͥઃܭΛ͢Δͷ͔ʁ w ΦϒδΣΫτࢦ޲ͱϞδϡʔϧ w (Pͷࢥ૝ͱύοέʔδઃܭ w (PΞϓϦέʔγϣϯઃܭ ΞδΣϯμ

Slide 6

Slide 6 text

w ͳͥઃܭΛ͢Δͷ͔ʁ w ΦϒδΣΫτࢦ޲ͱϞδϡʔϧ w (Pͷࢥ૝ͱύοέʔδઃܭ w (PΞϓϦέʔγϣϯઃܭ ΞδΣϯμ

Slide 7

Slide 7 text

ͳͥઃܭΛ͢Δͷ͔ʁ

Slide 8

Slide 8 text

w ਓؒ͸ඞͣؒҧ͑Δ w Ϧιʔε͸ৗʹ༗ݶ ιϑτ΢ΣΞ͸ਓ͕͍ؒͭͬͯ͘Δ

Slide 9

Slide 9 text

w ૝ఆ֎ͷৼΔ෣͍ όά ΁ͷίετΛ࠷খݶʹ w मਖ਼΁ͷίετΛ࠷খݶʹ ݶΒΕͨϦιʔεͰιϑτ΢ΣΞΛ
 ͭ͘ΔͨΊʹ

Slide 10

Slide 10 text

w Ϗδωεʹجͮ͘࡞ۀɾۀ຿ɾ࢓ࣄ υϝΠϯ ΛࣗಈԽ͢Δͷ͕ΞϓϦέʔγϣϯ։ൃ w ͜ΕΒ͸ৗʹมԽ͠ଓ͚Δ ΞϓϦέʔγϣϯ։ൃͷδϨϯϚ

Slide 11

Slide 11 text

w Ϗδωεʹجͮ͘࡞ۀɾۀ຿ɾ࢓ࣄ υϝΠϯ ΛࣗಈԽ͢Δͷ͕ΞϓϦέʔγϣϯ։ൃ w ͜ΕΒ͸ৗʹมԽ͠ଓ͚Δ ΞϓϦέʔγϣϯ։ൃͷδϨϯϚ ΞϓϦέʔγϣϯΤϯδχΞ͸
 ৗʹมԽ͠ଓ͚Δ΋ͷΛ
 ௥͍ଓ͚ͳ͚Ε͹ͳΒͳ͍

Slide 12

Slide 12 text

଎͘ਐΉ།Ұͷํ๏͸ɺ͏·͘ਐΉ͜ͱͰ͋Δɻ — Clean Architecture ୡਓʹֶͿιϑτ΢ΣΞͷߏ଄ͱઃܭ

Slide 13

Slide 13 text

w ࢓༷௨Γʹಈ࡞͢Δ͔ w ࢓༷มߋʹదԠͰ͖Δ͔ w ιϑτ΢ΣΞͷ࠶ར༻ੑ w FUD ιϑτ΢ΣΞʹٻΊΔ͜ͱ

Slide 14

Slide 14 text

w ίʔυͷมߋ͠΍͢͞ w ίʔυͷཧղ͠΍͢͞ɺՄಡੑ w FUD ͦͷͨΊʹඞཁͳ΋ͷ

Slide 15

Slide 15 text

w ։ൃऀ͕υϝΠϯϩδοΫʹूதͰ͖Δ w ਖ਼ղͰ͸ͳ͘ͱ΋ܾΊΔ͜ͱࣗମʹՁ஋͕͋Δ ઃܭɾΞʔΩςΫνϟͷՁ஋ *1: https://speakerdeck.com/sonatard/next-currency-gaego

Slide 16

Slide 16 text

w ͳͥઃܭΛ͢Δͷ͔ʁ w ΦϒδΣΫτࢦ޲ͱϞδϡʔϧ w (Pͷࢥ૝ͱύοέʔδઃܭ w (PΞϓϦέʔγϣϯઃܭ ΞδΣϯμ

Slide 17

Slide 17 text

ΦϒδΣΫτࢦ޲ͱϞδϡʔϧ

Slide 18

Slide 18 text

ΦϒδΣΫτࢦ޲Ϋϥεࢦ޲

Slide 19

Slide 19 text

w :FTBOEOP w $ݴޠΑΓΦϒδΣΫτࢦ޲ͳݴޠ w ΦϒδΣΫτࢦ޲͔Ͳ͏͔͸ਅِ஋Ͱ͸ͳ͍ (P͸ΦϒδΣΫτࢦ޲ݴޠ͔ʁ *1: https://golang.org/doc/faq#Is_Go_an_object-oriented_language *2: ΦϒδΣΫτࢦ޲ೖ໳ ୈ 2 ൛ ݪଇɾίϯηϓτ

Slide 20

Slide 20 text

w ιϑτ΢ΣΞͷ࣋ͭ΂͖ػೳͷ࢓༷͸ඇৗʹ੬͍ w ৗʹιϑτ΢ΣΞશମ͕มߋ͞ΕΔՄೳੑ͕
 ෇͖·ͱ͏ ػೳϕʔεͷϞσϦϯά

Slide 21

Slide 21 text

ྫ ίϯύΠϥ w MFYFS w QBSTFS w "45 ΦϒδΣΫτϕʔεͷϞσϦϯά

Slide 22

Slide 22 text

ίϯύΠϥʹ৽͍͠ػೳ͕௥Ճ͞Εͨͱͯ͠΋
 ΦϒδΣΫτʹมߋ͸ੜ͡ʹ͍͘ ΦϒδΣΫτϕʔεͷϞσϦϯά

Slide 23

Slide 23 text

ιϑτ΢ΣΞͷ࣋ͭ΂͖ػೳͰ͸ͳ͘ɺ
 ૢ࡞͢ΔΦϒδΣΫτͷܕ͔Βಋ͔ΕΔϞδϡʔϧ ΛجຊʹΞʔΩςΫνϟΛߏங͢Δ։ൃख๏ ΦϒδΣΫτࢦ޲ʹΑΔ։ൃ — ΦϒδΣΫτࢦ޲ೖ໳ ୈ 2 ൛ ݪଇɾίϯηϓτ (Ұ෦վม)

Slide 24

Slide 24 text

ιϑτ΢ΣΞͷ࣋ͭ΂͖ػೳͰ͸ͳ͘ɺ
 ૢ࡞͢ΔΦϒδΣΫτͷܕ͔Βಋ͔ΕΔϞδϡʔϧ ΛجຊʹΞʔΩςΫνϟΛߏங͢Δ։ൃख๏ ΦϒδΣΫτࢦ޲ʹΑΔ։ൃ — ΦϒδΣΫτࢦ޲ೖ໳ ୈ 2 ൛ ݪଇɾίϯηϓτ (Ұ෦վม)

Slide 25

Slide 25 text

w /P w ػೳΛ஌Βͳ͚Ε͹ιϑτ΢ΣΞΛߏஙͰ͖ͳ͍ w ػೳΑΓઌʹΦϒδΣΫτͷܕΛ෼ੳ͢Δ ػೳʹ͍ͭͯߟ͑Δ΂͖Ͱ͸ͳ͍ʁ

Slide 26

Slide 26 text

w QBDLBHF࠷খͷϞδϡʔϧ୯Ґ w (PNPEVMFTQBDLBHFͷίϨΫγϣϯ୯Ґ (PͷϞδϡʔϧγεςϜ

Slide 27

Slide 27 text

w มߋʹڧ͍ߏ଄Λͭ͘ΔͨΊ w ཧղ͠΍͍͢ߏ଄Λͭ͘ΔͨΊ w ૊Έ߹Θͤ΍͍͢ߏ଄Λͭ͘ΔͨΊ ͳͥϞδϡʔϧ͕ඞཁ͔ʁ

Slide 28

Slide 28 text

w ͳͥઃܭΛ͢Δͷ͔ʁ w ΦϒδΣΫτࢦ޲ͱϞδϡʔϧ w (Pͷࢥ૝ͱύοέʔδઃܭ w (PΞϓϦέʔγϣϯઃܭ ΞδΣϯμ

Slide 29

Slide 29 text

(Pͷࢥ૝ͱύοέʔδߏ੒

Slide 30

Slide 30 text

w l1BDLBHFYYYQSPWJEFT PSJNQMFNFOUT z͔Β
 ࢝·ΔυΩϡϝϯτ ඞ໊ͣࢺ͕ύοέʔδ໊ʹͳΔ w 4IPSU DPODJTF FWPDBUJWF w "WPJETUVUUFS w 40-*%ݪଇʹجͮ͘ (Pͷඪ४ύοέʔδͷಛ௃ *1: https://golang.org/doc/effective_go.html?#package-names

Slide 31

Slide 31 text

!IUUQ)5514FSWFS IUUQ4FSWFS "WPJETUVUUFS ٣Ի https://blog.golang.org/package-names

Slide 32

Slide 32 text

w 4JOHMF3FTQPOTJCJMJUZ1SJODJQBM w Ϟδϡʔϧ͸ͨͬͨҰͭͷΞΫλʔʹରͯ͠
 ੹຿Λෛ͏΂͖Ͱ͋Δ 4୯Ұ੹೚ݪଇ

Slide 33

Slide 33 text

w ύοέʔδ໊͕ද͢υϝΠϯʹͷΈ੹຿Λ࣋ͭ w JPˠೖग़ྗΛந৅Խͨ͠ΠϯλʔϑΣʔεͷఏڙ w GNUˠೖग़ྗͷϑΥʔϚοτ 4୯Ұ੹೚ݪଇ

Slide 34

Slide 34 text

w 0QFO$MPTFE1SJODJQBM w Ϟδϡʔϧ͸֦ுʹରͯ͠։͍͍ͯͯɺ
 मਖ਼ʹରͯ͠ด͍ͯ͡ͳ͚Ε͹ͳΒͳ͍ 0։์ด࠯ݪଇ

Slide 35

Slide 35 text

type nopCloser struct { io.Reader } func (nopCloser) Close() error { return nil } func NopCloser(r io.Reader) io.ReadCloser { return nopCloser{r} }

Slide 36

Slide 36 text

package cli func Run(cmd string, args []string) { switch cmd { case "echo": fmt.Println(strings.Join(args, " ")) case "reverse": reversed := reverse(args) fmt.Println(strings.Join(reversed, " ")) default: fmt.Println("unknown command") } } $ ./app echo foo bar foo bar

Slide 37

Slide 37 text

package cli type Command interface { Run(args []string) } func Run(cmd Command, args []string) { cmd.Run(args) }

Slide 38

Slide 38 text

package main type echoCommand struct{} func (c *echoCommand) Run(args []string) { // logic } type reverseCommand struct{} func (c *reverseCommand) Run(args []string) { // logic }

Slide 39

Slide 39 text

package main func main() { cmdName := os.Args[1] args := os.Args[2:] var cmd cli.Command switch cmdName { case "echo": cmd = &echoCommand{} case "reverse": cmd = &reverseCommand{} default: // unknown command } cli.Run(cmd, args) }

Slide 40

Slide 40 text

w ιϑτ΢ΣΞ͕બ୒ࢶΛఏڙ͠ͳ͚Ε͹ͳΒͳ͍ ࣌ɺͨͩҰͭͷϞδϡʔϧ͚͕ͩͦͷબ୒ࢶͷ͢ ΂ͯΛ೺Ѳ͢΂͖Ͱ͋Δ ୯Ұબ୒੹೚

Slide 41

Slide 41 text

package cli type CLI struct { Commands map[string]Command } func (c *CLI) Run(args []string) error { cmdName := args[0] cmd, ok := c.Commands[cmdName] if !ok { return errors.New("unknown command") } cmd.Run(args[1:]) return nil }

Slide 42

Slide 42 text

package main func main() { args := os.Args[1:] c := &cli.CLI{} c.Commands = map[string]cli.Command{ “echo": &echoCommand{}, "reverse": &reverseCommand{}, } c.Run(args) }

Slide 43

Slide 43 text

w 4ܕͷΦϒδΣΫτPͱ5ܕͷΦϒδΣΫτ P͕͋Γɺ5Λ࢖ͬͯఆٛ͞ΕͨϓϩάϥϜʹ ରͯ͠Pͷ୅ΘΓʹPΛ࢖ͬͯ΋ϓϩάϥϜ ͷৼΔ෣͍͕มΘΒͳ͍৔߹ɺ4͸5ͷ೿ੜܕ ͱݴ͑Δ -Ϧείϑͷஔ׵ݪଇ

Slide 44

Slide 44 text

3FDUBOHMF 4RVBSF $MJFOU

Slide 45

Slide 45 text

type Rectangle interface { SetX(x int) SetY(y int) } type Square struct { x, y int } func (s *Square) SetX(x int) { s.x, s.y = x, x } func (s *Square) SetY(y int) { s.x, s.y = y, y }

Slide 46

Slide 46 text

func TestRectangle(t *testing.T) { var r Rectangle = &Square{} expectedX, expectedY := 100, 200 r.SetX(100) r.SetY(200) if x := r.GetX(); x != expectedX { t.Errorf("x expected %d, but got %d", expectedX, x) } if y := r.GetY(); y != expectedY { t.Errorf("y expected %d, but got %d", expectedX, y) } }

Slide 47

Slide 47 text

w ΠϯλʔϑΣʔεͷΫϥΠΞϯτʹΫϥΠΞϯτ ͕ར༻͠ͳ͍ϝιου΁ͷґଘΛڧ੍ͯ͠͸ͳΒ ͳ͍ *ΠϯλʔϑΣʔε෼཭ͷݪଇ

Slide 48

Slide 48 text

w 5IFCJHHFSUIFJOUFSGBDF UIFXFBLFSUIF BCTUSBDUJPO w ඪ४ύοέʔδͷΠϯλʔϑΣʔε͸ඇৗʹ
 খ͘͞ɺগͳ͘อͨΕ͍ͯΔ *ΠϯλʔϑΣʔε෼཭ͷݪଇ *1: Go Proverbs (https://go-proverbs.github.io/) *2: The Go Blog - Organizing Go code

Slide 49

Slide 49 text

w JP3FBEFS JP8SJUFS w IUUQ)BOEMFS w FUD *ΠϯλʔϑΣʔε෼཭ͷݪଇ

Slide 50

Slide 50 text

w ্ҐϨϕϧͷϞδϡʔϧ͸ԼҐϨϕϧͷϞδϡʔϧʹґ ଘͯ͠͸ͳΒͳ͍ɻ྆ํͱ΋ந৅ʹґଘ͢΂͖Ͱ͋Δɻ w ந৅͸ৄࡉʹґଘͯ͠͸ͳΒͳ͍ɻৄࡉ͕ந৅ʹґଘ͢ ΂͖Ͱ͋Δɻ %ґଘؔ܎ٯసͷݪଇ

Slide 51

Slide 51 text

w *NQPSUDZDMFOPUBMMPXFE w ҆ఆͨ͠ந৅͸ґଘάϥϑͷԼҐϨϕϧ΁ɺ
 ৄࡉ͸্ҐϨϕϧ΁ %ґଘؔ܎ٯసͷݪଇ

Slide 52

Slide 52 text

w ΞʔΩςΫνϟΛઃܭ͠ɺ w ద੾ͳ໊લΛϞδϡʔϧ΁͚ͭɺ w ͦΕҎ֎ͷৄࡉ͸υΩϡϝϯτʹ࢒͢ w ݸਓతʹ ࠷΋कΒΕ͍ͯͳ͍ݪଇͩͱࢥ͏ %FTJHOUIFBSDIJUFDUVSF 
 OBNFUIFDPNQPOFOUT EPDVNFOUUIFEFUBJMT

Slide 53

Slide 53 text

(PΞϓϦέʔγϣϯͷઃܭ

Slide 54

Slide 54 text

w ϥΠϒϥϦͱ͸ҧ͍ɺ࣮ߦՄೳϑΝΠϧ ֎෦ʹΫϥΠΞϯτ͕ଘࡏ͢Δ
 ϒϥ΢βɺϞόΠϧɺϚΠΫϩαʔϏεɺFUD w ΫϥΠΞϯτʹఏڙ͢ΔϢʔεέʔε͕ଘࡏ͢Δ ΞϓϦέʔγϣϯ

Slide 55

Slide 55 text

w ϢʔεέʔεϩδοΫ
 ϢʔεέʔεΛ࣮ݱ͢ΔͨΊͷϩδοΫ w υϝΠϯϩδοΫ
 Ϣʔεέʔεʹґଘ͠ͳ͍ϩδοΫ ϢʔεέʔεϩδοΫɺυϝΠϯϩδοΫ

Slide 56

Slide 56 text

w 6*΍"1*ΠϯλʔϑΣʔεʹґଘ͢Δ w ϖʔδϯά෇͖ͷҰཡը໘ w ೖྗ஋Λݩʹͨ͠Ϣʔβొ࿥ w FUD ۩ମతͳϢʔεέʔεϩδοΫ

Slide 57

Slide 57 text

w Ϣʔεέʔεʹґଘ͠ͳ͍ w υϝΠϯ஌ࣝΛϞσϦϯά͠ɺ֤ཁૉΛ
 Ϟδϡʔϧ΁෼཭͢Δ w ৄ͘͠͸%%%*%%%Λࢀর υϝΠϯϩδοΫ

Slide 58

Slide 58 text

w (Pͷඪ४ύοέʔδͱಉ͡ํ਑Ͱ w 40-*%ݪଇΛकΔ w ໌֬ͳ໊ࢺΛύοέʔδ໊ʹ͢Δ w ύοέʔδ໊ͱΤϯςΟςΟ໊ΛৗʹηοτͰߟ͑Δ Ϟδϡʔϧ෼ׂͷ୯Ґ

Slide 59

Slide 59 text

w ίʔυ͚ͩͰ͸Θ͔Βͳ͍ɺΘ͔ΓͮΒ͍ৄࡉ΍ ࢓༷Λ࢒͢ w ϞδϡʔϧͷΫϥΠΞϯτʹͰ͖ΔݶΓ
 ࣮૷Λಡ·ͤͳ͍Α͏ʹ͢Δ υΩϡϝϯτ

Slide 60

Slide 60 text

type ResponseWriter interface { // WriteHeader sends an HTTP response header with the provided // status code. // // If WriteHeader is not called explicitly, the first call to Write // will trigger an implicit WriteHeader(http.StatusOK). // Thus explicit calls to WriteHeader are mainly used to // send error codes. // // The provided code must be a valid HTTP 1xx-5xx status code. // Only one header may be written. Go does not currently // support sending user-defined 1xx informational headers, // with the exception of 100-continue response header that the // Server sends automatically when the Request.Body is read. WriteHeader(statusCode int) }

Slide 61

Slide 61 text

type ResponseWriter interface { // WriteHeader sends an HTTP response header with the provided // status code. // // If WriteHeader is not called explicitly, the first call to Write // will trigger an implicit WriteHeader(http.StatusOK). // Thus explicit calls to WriteHeader are mainly used to // send error codes. // // The provided code must be a valid HTTP 1xx-5xx status code. // Only one header may be written. Go does not currently // support sending user-defined 1xx informational headers, // with the exception of 100-continue response header that the // Server sends automatically when the Request.Body is read. WriteHeader(statusCode int) }

Slide 62

Slide 62 text

·ͱΊ

Slide 63

Slide 63 text

υϝΠϯ஌ࣝΛे෼ʹಘΔ ҆ఆͨ͠ந৅Λݟ͚ͭͯɺܕͱ໊લΛ͚ͭΔ w ΞϓϦέʔγϣϯʹґଘ͠ͳ͍͜ͱ ಘΒΕͨܕΛ40-*%΍(Pͷࢥ૝ʹج͍ͮͯ
 ϞδϡʔϧԽ͢Δ Ϟδϡʔϧͷఆٛɾߏங

Slide 64

Slide 64 text

ػೳ Ϣʔεέʔε Λ೺Ѳ͢Δ ϞδϡʔϧΛ૊Έ߹Θ࣮ͤͯݱ͢Δ w ఆٛͨ͠Ϟδϡʔϧ಺ʹ࣮૷͠ͳ͍͜ͱ ΞϓϦέʔγϣϯͷߏங

Slide 65

Slide 65 text

w ͱ͸͍͑ɺઃܭ͸೉͍͠ w ϕετͳઃܭ͸ଘࡏ͠ͳ͍ w ঢ়گʹԠͯ͡ϕλʔͳઃܭΛݟ͚͍ͭͯ͜͏ ·ͱΊ

Slide 66

Slide 66 text

w ΞʔΩςΫνϟύλʔϯ΍ɺઃܭͷݪଇ w ͔ͳΓΘ͔Γ΍͍͕͢ɺ֤ݪଇͷৄࡉ͸
 ผͷຊͷ΄͏͕ৄ͍͠ $MFBO"SDIJUFDUVSF ୡਓʹֶͿιϑτ΢ΣΞͷߏ଄ͱઃܭ

Slide 67

Slide 67 text

w ΦϒδΣΫτࢦ޲ͷ໨తɺఆٛɺݪଇ w ϖʔδʂ w จষ͕೉ղ͕ͩɺΦϒδΣΫτࢦ޲ʹؔ͢Δ ͍͍ͩͨͷ͜ͱ͸ॻ͍ͯ͋Δ ΦϒδΣΫτࢦ޲ೖ໳ୈ൛ ݪଇɾίϯηϓτ

Slide 68

Slide 68 text

w %%%ຊ w υϝΠϯΛத৺ʹઃܭ͢Δ͜ͱͷॏཁੑ΍ཧ ࿦ɺͦͷख๏Λѻ͏ w ந৅తͳදݱ͕ଟͯ͘೉͍͠ ΤϦοΫɾΤϰΝϯεͷυϝΠϯ ۦಈઃܭ

Slide 69

Slide 69 text

w *%%%ຊ w %%%Λ࣮ࡍͷઃܭʹԠ༻͢Δ w %%%ຊΛಡΜͰͳ͍ͱΘ͔Βͳ͍఺΋͋Δ ࣮ફυϝΠϯۦಈઃܭ

Slide 70

Slide 70 text

w 5IF(P#MPHIUUQTCMPHHPMBOHPSH w 5IF(P1SPHSBNNJOH-BOHVBHF%PDVNFOUBUJPOIUUQTHPMBOHPSHEPD w 40-*%(P%FTJHOIUUQTEBWFDIFOFZOFUTPMJEHPEFTJHO w ʮ(PݴޠΒ͠͞ʯͱ͸Կ͔ʁ4JNQMJDJUZͷ఩ֶΛཧղ͠ɺ(P8BZʹԊͬͨ։ൃΛ ਐΊΔ͜ͱͷྑ͞
 IUUQTFNQMPZNFOUFOKBQBODPNFOHJOFFSIVCFOUSZ 8FC