Upgrade to Pro — share decks privately, control downloads, hide ads and more …

はてなのサービスを支えるGo / hatena.go #1 maku693

HAMADA Shota
January 31, 2024

はてなのサービスを支えるGo / hatena.go #1 maku693

hatena.go #1の登壇資料です。

HAMADA Shota

January 31, 2024
Tweet

Other Decks in Technology

Transcript

  1. 2015~2016年 • Go 1.5 ~ 1.7 • MackerelのサブシステムでGoが採用されは じめる •

    Mackerel以外にも徐々に利用が広まる ◦ 社内むけコマンドラインツール ◦ はてラボ人間性センター
  2. • Go 1.16 ~ 1.21 • マンガノ ◦ SPA/BFF向けGraphQL APIをGoで実装

    • はてなのサービス基盤でGoが採用される • チーム横断組織「Goサブ会」発足 2021~2023年
  3. • GraphQL ◦ gqlgen, graphql-go ◦ ほぼ全てgqlgen • gRPC ◦

    システム間通信に採用 • OpenAPI ◦ go-swagger, oapi-codegen • スキーマファースト ◦ クライアントを自動生成できる ◦ 分業しやすい API
  4. DBアクセス • sqlx ◦ RDBを使うシステムではほぼ間違いなく入っている ◦ ORMやクエリビルダが不要な場合のデフォルトの選択肢 • クエリビルダ ◦

    goqu, squirrel • ORM ◦ gorm, sqlboiler, ent • ORMよりクエリビルダの採用例が多い ◦ PerlでTengよりSQL::Makerがよく使われていたのに似ている
  5. • エントリポイント (main) が複数あるサービスはほぼ レイヤード ◦ 複数エントリポイントから共通のユースケースを利用するのに 必要 ◦ フラットな場合ユースケースの置き場所が自明でない

    • フラット構造の場合はDIがなくてもなんとかなるが… ◦ これもエントリポイントが増えてくると初期化処理が重複して しまう パッケージ構造
  6. ライブラリ選定 • リフレクションよりコード生成が人気 ◦ wire, gomock, gqlgen, oapi-codegen, ent, etc…

    ◦ 独自のジェネレータを自作している場合も • 重厚なフレームワークより軽量なライブラリ の組み合わせ
  7. 紹介したライブラリ • DI ◦ https://github.com/google/wire • テスト ◦ https://github.com/stretchr/testify ◦

    https://github.com/gotestyourself/gotest.tools ◦ https://github.com/onsi/ginkgo • モック ◦ https://github.com/uber-go/mock • ロガー ◦ https://github.com/uber-go/zap ◦ https://github.com/sirupsen/logrus • HTTPサーバ ◦ https://github.com/labstack/echo ◦ https://github.com/go-chi/chi ◦ https://github.com/gin-gonic/gin
  8. 紹介したライブラリ • API ◦ https://github.com/99designs/gqlgen ◦ https://github.com/graphql-go/graphql ◦ https://github.com/grpc/grpc-go ◦

    https://github.com/go-swagger/go-swagger ◦ https://github.com/deepmap/oapi-codegen • DB ◦ https://github.com/jmoiron/sqlx ◦ https://github.com/doug-martin/goqu ◦ https://github.com/Masterminds/squirrel ◦ https://github.com/go-gorm/gorm ◦ https://github.com/volatiletech/sqlboiler ◦ https://github.com/ent/ent