Slide 1

Slide 1 text

Golang in LINE MUSIC TW Wei 2020.9.23

Slide 2

Slide 2 text

Who am I • Name: wei • Company: LINE Taiwan • Project: LINE MUSIC • School: NTUT • Interest: 看天之驕女

Slide 3

Slide 3 text

Agenda • What is LINE MUSIC • System Architecture • APIGW Server • How to build RESTful API Server • How to build GraphQL Server • How to connect Other HTTP API • Content Server • How to build gRPC Server • How to connect MySQL • How to connect Redis • How to connect MongoDB • Event Log Server • How to connect Kafka • How to connect Elasticsearch • Content Sync Server • How to build WebSocket Server • Project Structure • Dependency Injection • Config Manage • Testing tools • Develop tools

Slide 4

Slide 4 text

What is LINE MUSIC • LINE APP Profile BGM / RT / RBT • Share music to LINE APP • AIDJ • Recommendation

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

APIGW

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

How to build RESTful API Server (Gin) • Links • https://gin-gonic.com/zh-tw • https://github.com/gin-gonic/gin • Feature • Routing • Bind Path • Bind request body and validation • Custom Middleware

Slide 9

Slide 9 text

Gin Routing

Slide 10

Slide 10 text

Gin Bind Path

Slide 11

Slide 11 text

Gin Bind request body and validation

Slide 12

Slide 12 text

Gin Custom Middleware

Slide 13

Slide 13 text

How to build GraphQL Server (gqlgen) • Links • https://gqlgen.com/ • https://github.com/99designs/gqlgen • Feature • CodeGen from GraphQL Schema (Model、Resolvers) • Intergration with Gin • Limit Query Complexity • APQ、Apollo Federation

Slide 14

Slide 14 text

CodeGen from GraphQL Schema (gqlgen)

Slide 15

Slide 15 text

Intergration with Gin (gqlgen)

Slide 16

Slide 16 text

Limit Query Complexity (gqlgen)

Slide 17

Slide 17 text

How to connect Other HTTP API (Resty) • Links • https://github.com/go-resty/resty • Feature • GET, POST, PUT, DELETE, HEAD, PATCH, OPTIONS • Request header, query, path param • Request body: string, []byte, struct, map, slice and io.Reader (Auto detects Content-Type) • Retry • Request and Response middlewares

Slide 18

Slide 18 text

Simple Request (Resty)

Slide 19

Slide 19 text

Request and Response middlewares (Resty)

Slide 20

Slide 20 text

Content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

How to build gRPC Server (grpc-go) • Links • https://github.com/grpc/grpc-go • https://github.com/golang/protobuf/tree/master/protoc-gen-go • Feature • CodeGen from protobuf (Server、Client) • Health check • Retry • Interceptor

Slide 23

Slide 23 text

CodeGen from protobuf (protoc-gen-go)

Slide 24

Slide 24 text

CodeGen from protobuf (protoc-gen-go)

Slide 25

Slide 25 text

CodeGen from protobuf (protoc-gen-go)

Slide 26

Slide 26 text

CodeGen from protobuf (protoc-gen-go)

Slide 27

Slide 27 text

Health check, Retry, Interceptor (grpc-go)

Slide 28

Slide 28 text

How to connect MySQL (GORM) • Links • https://gorm.io/zh_CN • https://github.com/go-gorm/gorm • Feature • ORM • Preload • Hooks • Auto Migration

Slide 29

Slide 29 text

Link to database

Slide 30

Slide 30 text

ORM (GORM)

Slide 31

Slide 31 text

Preload (GORM)

Slide 32

Slide 32 text

Hooks (GORM)

Slide 33

Slide 33 text

Auto Migration (GORM)

Slide 34

Slide 34 text

How to connect Redis (go-redis) • Links • https://github.com/go-redis/redis • Feature • Single, Cluster • Operation • Pub / Sub

Slide 35

Slide 35 text

Single, Cluster (go-redis)

Slide 36

Slide 36 text

Operation (go-redis)

Slide 37

Slide 37 text

Pub / Sub (go-redis)

Slide 38

Slide 38 text

How to connect MongoDB (mongo-go-driver) • Links • https://github.com/mongodb/mongo-go-driver

Slide 39

Slide 39 text

How to connect MongoDB (mongo-go-driver)

Slide 40

Slide 40 text

Event Log

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

How to connect Kafka (sarama) • Links • https://github.com/Shopify/sarama • Feature • Producer • Consumer / Consumer Group

Slide 43

Slide 43 text

Producer (sarama)

Slide 44

Slide 44 text

Consumer (sarama)

Slide 45

Slide 45 text

Consumer (sarama)

Slide 46

Slide 46 text

How to connect Elasticsearch (go- elasticsearch) • Links • https://github.com/elastic/go-elasticsearch

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

How to build WebSocket Server (melody) • Links • https://github.com/olahol/melody

Slide 49

Slide 49 text

How to build WebSocket Server (melody)

Slide 50

Slide 50 text

Project Structure • https://github.com/golang-standards/project-layout

Slide 51

Slide 51 text

Dependency Injection • https://github.com/uber-go/dig • https://github.com/uber-go/fx

Slide 52

Slide 52 text

Dependency Injection (fx)

Slide 53

Slide 53 text

Dependency Injection (fx)

Slide 54

Slide 54 text

Dependency Injection (fx) …..

Slide 55

Slide 55 text

Dependency Injection (fx)

Slide 56

Slide 56 text

Config Manage • https://github.com/spf13/viper

Slide 57

Slide 57 text

Config Manage

Slide 58

Slide 58 text

Testing tools • https://github.com/stretchr/testify

Slide 59

Slide 59 text

Testing tools • https://github.com/smartystreets/goconvey

Slide 60

Slide 60 text

Testing tools

Slide 61

Slide 61 text

Develop tools • https://github.com/silenceper/gowatch • https://github.com/Shelnutt2/db2struct