Golang in LINE MUSIC TW

Golang in LINE MUSIC TW

by Wei Wan @Golang Taipei Gathering #54 https://www.meetup.com/golang-taipei-meetup/events/272926722/

2102a6b8760bd6f57f672805723dd83a?s=128

line_developers_tw

September 23, 2020
Tweet

Transcript

  1. Golang in LINE MUSIC TW Wei 2020.9.23

  2. Who am I • Name: wei • Company: LINE Taiwan

    • Project: LINE MUSIC • School: NTUT • Interest: 看天之驕女
  3. 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
  4. What is LINE MUSIC • LINE APP Profile BGM /

    RT / RBT • Share music to LINE APP • AIDJ • Recommendation
  5. None
  6. APIGW

  7. None
  8. 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
  9. Gin Routing

  10. Gin Bind Path

  11. Gin Bind request body and validation

  12. Gin Custom Middleware

  13. 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
  14. CodeGen from GraphQL Schema (gqlgen)

  15. Intergration with Gin (gqlgen)

  16. Limit Query Complexity (gqlgen)

  17. 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
  18. Simple Request (Resty)

  19. Request and Response middlewares (Resty)

  20. Content

  21. None
  22. 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
  23. CodeGen from protobuf (protoc-gen-go)

  24. CodeGen from protobuf (protoc-gen-go)

  25. CodeGen from protobuf (protoc-gen-go)

  26. CodeGen from protobuf (protoc-gen-go)

  27. Health check, Retry, Interceptor (grpc-go)

  28. How to connect MySQL (GORM) • Links • https://gorm.io/zh_CN •

    https://github.com/go-gorm/gorm • Feature • ORM • Preload • Hooks • Auto Migration
  29. Link to database

  30. ORM (GORM)

  31. Preload (GORM)

  32. Hooks (GORM)

  33. Auto Migration (GORM)

  34. How to connect Redis (go-redis) • Links • https://github.com/go-redis/redis •

    Feature • Single, Cluster • Operation • Pub / Sub
  35. Single, Cluster (go-redis)

  36. Operation (go-redis)

  37. Pub / Sub (go-redis)

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

  39. How to connect MongoDB (mongo-go-driver)

  40. Event Log

  41. None
  42. How to connect Kafka (sarama) • Links • https://github.com/Shopify/sarama •

    Feature • Producer • Consumer / Consumer Group
  43. Producer (sarama)

  44. Consumer (sarama)

  45. Consumer (sarama)

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

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

  49. How to build WebSocket Server (melody)

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

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

  52. Dependency Injection (fx)

  53. Dependency Injection (fx)

  54. Dependency Injection (fx) …..

  55. Dependency Injection (fx)

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

  57. Config Manage

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

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

  60. Testing tools

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