Slide 1

Slide 1 text

ΠϝʔδͰཧղ͢Δ

Slide 2

Slide 2 text

ࠓ೔ͷΰʔϧ ɾH31$ͬͯͳʹʁ ɾ31$ͬͯͳʹʁ ɾͲ͏΍࣮ͬͯ૷͢Δͷʁ

Slide 3

Slide 3 text

ͬͯͳʹʁ

Slide 4

Slide 4 text

H31$ (PPHMF͕࡞ͬͨ31$ϑϨʔϜϫʔΫ

Slide 5

Slide 5 text

31$ͬͯͳʹʁ

Slide 6

Slide 6 text

31$ 3FNPUF1SPDFEVSF$BMM

Slide 7

Slide 7 text

31$ DMJFOU͕ࣗ਎ͷϝιουΛ࣮ߦ͢Δײ֮Ͱ TFSWFS্ͷϝιουΛ࣮ߦͰ͖Δ͘͠Έ

Slide 8

Slide 8 text

ͭ·ΓɺͲ͏͍͏͜ͱʁ

Slide 9

Slide 9 text

DMJFOUͱTFSWFSʹಉ໊ϝιου͕͋ͬͯ IUUQTJDPOTDPNJDPOTTFUTFSWFS DMJFOU TFSWFS Find() Find()

Slide 10

Slide 10 text

DMJFOU͕ϝιουΛ࣮ߦ͢Δͱ DMJFOU TFSWFS Find() Find() IUUQTJDPOTDPNJDPOTTFUTFSWFS

Slide 11

Slide 11 text

TFSWFSଆͷಉ໊ϝιου͕࣮ߦ͞Ε DMJFOU TFSWFS Find() Find() SFRVFTU IUUQTJDPOTDPNJDPOTTFUTFSWFS

Slide 12

Slide 12 text

ͦͷฦΓ஋͕DMJFOUଆͷฦΓ஋ʹͳΔ DMJFOU TFSWFS Find() Find() SFRVFTU SFTQPOTF IUUQTJDPOTDPNJDPOTTFUTFSWFS

Slide 13

Slide 13 text

H31$͸͜ͷؒΛ͏·͘΍ͬͯ͘ΕΔ DMJFOU TFSWFS Find() Find() SFRVFTU SFTQPOTF IUUQTJDPOTDPNJDPOTTFUTFSWFS

Slide 14

Slide 14 text

const res = axios.get("/api/v1/users/1") js req := FindRequest({ID: 1}) res, err = user.Find(req) go 3&45 31$ ͜Μͳ࢖͍ํ͕Ͱ͖·͢

Slide 15

Slide 15 text

Ͳ͏΍࣮ͬͯ૷͢Δͷʁ

Slide 16

Slide 16 text

31$Λ࣮ݱ͢Δʹ͸ SFRVFTU DMJFOU TFSWFS SFTQPOTF IUUQTJDPOTDPNJDPOTTFUTFSWFS

Slide 17

Slide 17 text

ڞ௨ೝ͕ࣝඞཁ SFRVFTU DMJFOU TFSWFS SFTQPOTF ϝιουͷ໊લ ϦΫΤετͷܗࣜ Ϩεϙϯεͷܗࣜ IUUQTJDPOTDPNJDPOTTFUTFSWFS

Slide 18

Slide 18 text

ͦΕ͕ɺQSPUPϑΝΠϧ SFRVFTU DMJFOU TFSWFS SFTQPOTF QSPUP IUUQTJDPOTDPNJDPOTTFUTFSWFS

Slide 19

Slide 19 text

QSPUPϑΝΠϧͷྫ service User { rpc Find(FindRequest) returns (FindResponse) {} } message FindRequest { int32 id = 1; } message FindResponse { string name = 1; } user_service.proto

Slide 20

Slide 20 text

QSPUPϑΝΠϧͷྫ user_service.proto ϦΫΤετͷܗࣜ Ϩεϙϯεͷܗࣜ service User { rpc Find(FindRequest) returns (FindResponse) {} } message FindRequest { int32 id = 1; } message FindResponse { string name = 1; }

Slide 21

Slide 21 text

service User { rpc Find(FindRequest) returns (FindResponse) {} } message FindRequest { int32 id = 1; } message FindResponse { string name = 1; } QSPUPϑΝΠϧͷྫ user_service.proto ˢϝιουͷఆٛ

Slide 22

Slide 22 text

QSPUP QCHP ࣍ʹɺΠϯλʔϑΣʔεΛੜ੒͢Δ QSPUPD QSPUPDΠϯλʔϑΣʔεΛੜ੒͢ΔͨΊͷίϚϯυ

Slide 23

Slide 23 text

QSPUP QCHP ࣍ʹɺΠϯλʔϑΣʔεΛੜ੒͢Δ QSPUPD ͍ΖΜͳJOUFSGBDF΍GVOD͕ࣗಈੜ੒ ͞ΕΔɽਓ͸Ұ੾͍͡Βͳ͍

Slide 24

Slide 24 text

ॏཁͳ෦෼͚ͩϐοΫΞοϓ type UserServer interface { Find( context.Context, *FindRequest ) (*FindResponse, error) } user_service.pb.go αʔόଆͷΠϯλʔϑΣʔε αʔόଆ͸͜Εʹ߹ΘͤͯϝιουΛ࣮૷͢Δ

Slide 25

Slide 25 text

ॏཁͳ෦෼͚ͩϐοΫΞοϓ type UserClient interface { Find( ctx context.Context, in *FindRequest, opts ...grpc.CallOption ) (*FindResponse, error) } ΫϥΠΞϯτଆͷΠϯλʔϑΣʔε ΫϥΠΞϯτଆ͸͜Εʹ߹ΘͤͯϝιουΛ࢖͏ user_service.pb.go

Slide 26

Slide 26 text

ॏཁͳ෦෼͚ͩϐοΫΞοϓ func (c *userClient) Find( ctx context.Context, in *FindRequest, opts ...grpc.CallOption ) (*FindResponse, error) { out := new(FindResponse) err := c.cc.Invoke( ctx, "/user_service.User/Find", in, out, opts... ) if err != nil { return nil, err } return out, nil } ΫϥΠΞϯτଆͷϝιου ΫϥΠΞϯτଆ͕ݺͼग़͢ϝιου͸࣮૷ࡁΈ user_service.pb.go

Slide 27

Slide 27 text

QSPUP QCHP ͪͳΈʹɺෳ਺ݴޠʹରԠ͍ͯ͠Δ SC KBWB

Slide 28

Slide 28 text

αʔόଆͷ࢖͍ํ ؆ུ൛ import pb "path/to/pb.go" type server struct{} func (s *server) Find( ctx context.Context, in *pb.FindRequest ) (*pb.FindResponse, error) { user := db.Find(&user) out := &pb.FindResponse{name: user.name} return out, nil } s := grpc.NewServer() pb.RegisterUserServer(s, &server{}) s.Serve(lis) server/main.go

Slide 29

Slide 29 text

import pb "path/to/pb.go" type server struct{} func (s *server) Find( ctx context.Context, in *pb.FindRequest ) (*pb.FindResponse, error) { user := db.Find(&user) out := &pb.FindResponse{name: user.name} return out, nil } s := grpc.NewServer() pb.RegisterUserServer(s, &server{}) s.Serve(lis) αʔόଆͷ࢖͍ํ ؆ུ൛ server/main.go %#͔Β஋Λ औಘͯ͠ฦ͢ αʔόͷ্ཱͪ͛

Slide 30

Slide 30 text

ΫϥΠΞϯτଆͷ࢖͍ํ ؆ུ൛ import pb "path/to/pb.go" c := pb.NewUserClient(conn) req := &pb.FindRequest{ id: 1, } resp, err := c.Find(context.Background(), req) if err != nil { log.Fatal(err) } log.Println("Name: ", resp.name) // #=> Name: alice client/main.go

Slide 31

Slide 31 text

ΫϥΠΞϯτଆͷ࢖͍ํ ؆ུ൛ import pb "path/to/pb.go" c := pb.NewUserClient(conn) req := &pb.FindRequest{ Name: "alice", } resp, err := c.Find(context.Background(), req) if err != nil { log.Fatal(err) } log.Println("Name: ", resp.name) // #=> Name: alice client/main.go αʔόଆͷFind()ͷฦΓ஋

Slide 32

Slide 32 text

ࠓ೔ͷ·ͱΊ H31$ͬͯͳʹʁ ˠ(PPHMF͕࡞ͬͨ31$ϑϨʔϜϫʔΫ 31$ͬͯͳʹʁ ˠΫϥΠΞϯτ͔ΒαʔόͷϝιουΛݺͿ H31$Λ࢖͏ʹ͸ʁ ˠQSPUPϑΝΠϧΛॻ͍ͯΠϯλʔϑΣʔεΛ ɹੜ੒͢Δ ˠੜ੒͞ΕͨΠϯλʔϑΣʔεΛ࢖࣮ͬͯ૷͢Δ