Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
http.RoundTripper Tips
Search
Naoya.i
November 13, 2021
Programming
0
560
http.RoundTripper Tips
"今日から使えるhttp.RoundTripper Tips" at Go Conference 2021 Autumn
Naoya.i
November 13, 2021
Tweet
Share
More Decks by Naoya.i
See All by Naoya.i
Retty × LeSSの取り組みと工夫 / Large-Scale Scrum in Retty
nao_mk2
2
1.3k
モブとソロを織り交ぜてハイアウトプットなチーム開発 / High output with swarming and solo work
nao_mk2
2
2.3k
問題解決会になったふりかえりからの脱却 / Beyond gloomy retrospective
nao_mk2
0
1.3k
チームの力を高めるモブワークを始めよう! / How To Mob Work
nao_mk2
1
2.2k
Other Decks in Programming
See All in Programming
Goのmultiple errorsについて (2024年4月版)
syumai
4
1.2k
Site Reliability Engineering for GMO
pyama86
9
1.1k
Git Lint
bkuhlmann
4
770
Sheets API使ってみた
toshi0383
2
170
冗長なエラーログを削減し、スタックトレースを手に入れる / Reducing Verbose Error Logs and Obtaining Stack Traces
upamune
0
1.1k
Hanami and htmx
bkuhlmann
0
230
大規模Reactアプリのリアーキテクチャ~8万行のTanStack Query移行の軌跡~
kj455
4
1k
Compose-View Interop in Practice (mDevCamp 2024)
stewemetal
0
170
Build Apps for iOS, Android & Desktop in 100% Kotlin With Compose Multiplatform (mDevCamp 2024)
zsmb
0
480
はてなにおける CSS Modules、及び CSS Modules に足りないもの / CSS Modules in Hatena, and CSS Modules missing parts
mizdra
7
1k
Go製Webアプリケーションのエラーとの向き合い方大全、あるいはやっぱりスタックトレース欲しいやん / Kyoto.go #50
utgwkk
6
1.9k
Let's learn code review
riofujimon
2
610
Featured
See All Featured
Typedesign – Prime Four
hannesfritz
36
2.1k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
123
39k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
126
32k
Rebuilding a faster, lazier Slack
samanthasiow
74
8.3k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
117
18k
The Mythical Team-Month
searls
217
42k
How to Ace a Technical Interview
jacobian
273
22k
Designing Experiences People Love
moore
136
23k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
275
13k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
14
8.4k
It's Worth the Effort
3n
180
27k
Unsuck your backbone
ammeep
664
57k
Transcript
今日から使えるhttp.RoundTripper Tips
池田 直弥(いけだ なおや) 自己紹介 Nao_Mk2 2019年 Retty入社 技術的にはバックエンド寄りが好き 仕事ではフロントエンドもインフラもやります ふりかえりは大好き
$ go version go version go1.17.2 darwin/amd64 今回のスライドの動作確認バージョン
エンジニア募集中! 3 ITで新たな食体験を提供していく「 Retty」のプロダ クト開発に携わるバックエンドエンジニアを募集し ます。 マイクロサービス化、新規事業など一緒に Goで開 発しませんか。 Go
Conferenceの発表で盛り込めなかった話や 残念ながら採択されなかったプロポーザルの話、 Go Conferenceに参加してみての感想戦、 Retty におけるGoでのプロダクト開発など、ざっくばらん にお話いたします!
http.RoundTripperの役割 (c *Client) Do(req *Request) send(ireq *Request, rt RoundTripper, deadline
time.Time) net/http/client.go (t *Transport) RoundTrip(req *Request) net/http/roundtrip.go (t *Transport) roundTrip(req *Request) net/http/transport.go (t *Transport) dialConn(ctx context.Context, cm connectMethod) type RoundTripper interface { RoundTrip(*Request) (*Response, error) } http.clientの通信は実質RoundTripperが担う
インタフェースなので扱いやすい! インタフェースの実装で好きな処理を埋め込める APMツールのエージェントもRoundTripperを活かしている https://github.com/DataDog/dd-trace-go/blob/v1/contrib/net/http/roundtripper.go ちょっとした実装でとっても便利!
便利Tips 3選 https://github.com/Nao-Mk2/go-roundtripper-tips
ロギング https://github.com/Nao-Mk2/go-roundtripper-tips/blob/main/logging/logging.go 通信内容をお手軽にロギング
使い所 • エラー調査に役立つ外部通信ログ ◦ Request / Response Bodyを記録 ▪ Bodyは直接操作せずクローンして扱う
▪ セキュリティ的に記録してOKな内容かは考慮
モック https://github.com/Nao-Mk2/go-roundtripper-tips/blob/main/mocking/mocking.go 通信しないモックが簡単
• 通信しないダミー実装 ◦ 任意の値を返すダミーでモックしながら開発 • ユニットテストのモック 使い所
リトライ https://github.com/Nao-Mk2/go-roundtripper-tips/blob/main/retrying/retrying.go 任意のリトライ機構が簡単
• シンプルなリトライ • Exponential Backoff 使い所 ステータスコードのみを見てハンドリングする RoundTripperインタフェースのコメントにResponse Bodyを 解釈すべきではないと記載がある
http.RoundTripperを活かして 楽しいGo Life!