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
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
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
7
2.2k
Java 27新機能 / Java 27 new features
kishida
2
170
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
380
海上で動くGoサーバー: goroutineとchannelでさばく航行データストリーム
atsuki_seo
0
910
市販E-Readerを乗っ取れ 〜Embedded Swiftで電子ペーパーガジェットを制御する〜
trickart
0
200
Are APIs Still Relevant in the AI Era?
soyuka
0
300
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
650
新卒PdEのリアル
ryu1013
1
510
MVNOの申込からeSIM開通までをiOSアプリでつなぐ- 本人確認・MNP・通信事業者基盤をまたぐ実装
satotakeshi
0
460
setup-vp GitLab対応の裏側
naokihaba
0
120
手動確認はもう限界 〜XCUITestでCustom URL Schemeの遷移を起動種別ごとに自動テストする〜 / Testing Custom URL Schemes with XCUITest
otouto
0
330
XP祭りでしか伝わらないフリップネタ #xpjug
murabayashi
0
150
Featured
See All Featured
Context Engineering - Making Every Token Count
addyosmani
9
1.2k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
340
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
The SEO identity crisis: Don't let AI make you average
varn
0
560
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
730
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
5
730
Bash Introduction
62gerente
615
220k
Making Projects Easy
brettharned
120
6.8k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
200
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
240
Marketing to machines
jonoalderson
1
5.8k
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!