Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
http.RoundTripper Tips
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Naoya.i
November 13, 2021
Programming
910
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
http.RoundTripper Tips
"今日から使えるhttp.RoundTripper Tips" at Go Conference 2021 Autumn
Naoya.i
November 13, 2021
More Decks by Naoya.i
See All by Naoya.i
CLIであることを活かしたGitHub Copilot CLI活用術 / GitHub Copilot CLI Pro Tips & Tricks
nao_mk2
1
1.5k
Retty × LeSSの取り組みと工夫 / Large-Scale Scrum in Retty
nao_mk2
2
1.7k
モブとソロを織り交ぜてハイアウトプットなチーム開発 / High output with swarming and solo work
nao_mk2
2
2.9k
問題解決会になったふりかえりからの脱却 / Beyond gloomy retrospective
nao_mk2
0
1.7k
チームの力を高めるモブワークを始めよう! / How To Mob Work
nao_mk2
1
3.1k
Other Decks in Programming
See All in Programming
Intent as Code
shoppingjaws
6
1.1k
Turning Architecture into Unit Tests in the AI Era (NSSpain XIV)
steliosf
PRO
1
120
Omarchy Tokyo やると聞いて UMPC 買ってセットアップしてきた
mtsmfm
0
190
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
310
大喜利で理解するLLM as a Judge / Understanding LLM-as-a-Judge through Ogiri
rockname
0
180
手動確認はもう限界 〜XCUITestでCustom URL Schemeの遷移を起動種別ごとに自動テストする〜 / Testing Custom URL Schemes with XCUITest
otouto
0
360
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
5.2k
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
29
13k
Agents on Rails - Rails at Scale 2026
irinanazarova
0
300
選挙速報を多くのユーザーへ 届ける Live Activities 設計
hamayokokuririn
0
190
TiDB Cloudのカスタムコントローラーによるオートスケール対応
takaidohigasi
0
140
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
730
Featured
See All Featured
Mobile First: as difficult as doing things right
swwweet
225
10k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
270
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
380
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
66k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.8k
WENDY [Excerpt]
tessaabrams
14
39k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.3k
It's Worth the Effort
3n
188
29k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
58k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
960
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
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!