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
それでも私はContextに値を詰めたい | Go Conference 2025 / go ...
Search
Yoichiro Shimizu
September 28, 2025
Technology
2.4k
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
それでも私はContextに値を詰めたい | Go Conference 2025 / go conference 2025 fill context
2025/09/28 Go Conference 2025で発表したLT資料です。
https://gocon.jp/2025/talks/958590/
Yoichiro Shimizu
September 28, 2025
More Decks by Yoichiro Shimizu
See All by Yoichiro Shimizu
synctest時代のhttptest Go 1.27で変わるHTTPサーバテストの裏側 / go conference2026 synctest and httptest
budougumi0617
1
3.1k
GoのWebプロダクトに途中参加するときのキャッチアップ #layerxgo / How to catch up Go web product
budougumi0617
6
1.1k
今日から始めるGo / Starting Go from Today
budougumi0617
3
2.3k
BASE BANKチームの技術選定と歴史 / how to decide technology selection for startup
budougumi0617
1
5k
New Relicを使った Observabilityの実現方法と活用例 / gocon 2022 spring after talk
budougumi0617
0
3.7k
testingパッケージを使った Webアプリケーションテスト 単体テストからE2Eテストまで / gocon2022spring
budougumi0617
6
4.2k
Go WebアプリケーションでNew Relic APMをフル活用するためのOSS 3選 / introduce oss for newrelic
budougumi0617
3
3.7k
ゆるふわ分散トレースはじめました / start casual distributed trace
budougumi0617
0
1.8k
PHPでつくるインタプリタ入門 / introduction interpreter by PHP
budougumi0617
0
3.7k
Other Decks in Technology
See All in Technology
Antigravity SDK for the Java Developer
glaforge
0
190
Harness Engineering on Rails
joelq
0
420
データ_AIの事業の勝敗をわけるもの
nek0128
1
480
ボードゲームの遊び相手をFoundation Modelsで作る / iOSDC Japan 2026
genda
0
150
What the customer really needed
kawaguti
PRO
3
220
人間はどの意思決定を手放せるのか
kawasima
15
8.1k
aws-iot-platform-architecture-use-cases.pdf
ma2shita
0
600
Oracle Cloud Infrastructure(OCI):Onboarding Session(はじめてのOCI/Oracle Supportご利⽤ガイド)
oracle4engineer
PRO
2
20k
AIに書かせて、プラットフォームで縛る ― EKSプラットフォームで実践した責任境界と権限設計
elmodev09
0
240
【技術的負債conf】事業成長に伴う技術的負債の説明責任とAIによるモニタリング、認知的負債について
i35_267
4
2.1k
Azure Serverless 2026:Production-ready な AI エージェント基盤 / Azure Serverless 2026: Production-Ready AI Agent Platform
miyake
2
570
SREの視点で考えるSIEM活用術 〜AWS環境でのセキュリティ強化〜
cscengineer
PRO
0
320
Featured
See All Featured
How GitHub (no longer) Works
holman
316
150k
エンジニアに許された特別な時間の終わり
watany
109
250k
Visualization
eitanlees
153
17k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
Site-Speed That Sticks
csswizardry
13
1.5k
Ruling the World: When Life Gets Gamed
codingconduct
0
360
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
420
Game over? The fight for quality and originality in the time of robots
wayneb77
1
290
Six Lessons from altMBA
skipperchong
29
4.5k
Building a Scalable Design System with Sketch
lauravandoore
464
34k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
700
Agile that works and the tools we love
rasmusluckow
331
22k
Transcript
© LayerX Inc. それでも私はContextに値を詰めたい 2025/09/28 Go Conference 2025 @budougumi0617 /
LayerX
主にWebサービスにおける リクエストコンテキストの話をします
📝おさらい
© LayerX Inc. 4 出⼒はどうなる?
© LayerX Inc. 5 • それはそう ⼦(呼び出し先)のWithValueは親(呼び出し元)から⾒えない
Webサーバあるある
© LayerX Inc. 7 • 会社IDやユーザーIDをリクエストのログに付与しておきたい Webサーバあるある
© LayerX Inc. 8 よくあるパターン: 認証ミドルウェア‧リクエストログミドルウェア
🤔困るとき
© LayerX Inc. 10 • GoでクレジットカードやETCカードを作ってます! 突然ですがお仕事紹介
© LayerX Inc. 11 • ⾃社の認証情報が⼊っていないリクエストを処理する • クレジットカードで決済があったとき ◦ 💳
外部決済システム → 🧾決済リクエスト → ⾃社サーバ • 利⽤料のお⽀払い(⼝座振替情報) ◦ 🏦 外部⾦融機関 → 💰⼊⾦リクエスト → ⾃社サーバ(消込) そうなるとこう
© LayerX Inc. 12 ビジネスロジックの中で会社を特定しかない
© LayerX Inc. 13 • それはそう 再掲: ⼦のWithValueは親から⾒えない
© LayerX Inc. 14 これがやりたい
© LayerX Inc. 15 • デコレータパターンで伝播する • contextオブジェクトにポインタ構造体を詰める 親のcontextにデータを詰める(渡す)アイデア
© LayerX Inc. 16 • Setterを追加したハコを親から渡しておく デコレータパターンで伝播する
© LayerX Inc. 17 デコレータパターンで伝播する
© LayerX Inc. 18 デコレータパターンで伝播する
© LayerX Inc. 19 デコレータパターンで伝播する デコレータ🐭 「http.ResponseWriter (を満たす実装)です!」 コンパイラ🤖 「よし通れ!」
例: func(w http.ResponseWriter, r *http.Request)の場合
© LayerX Inc. 20 👍 Pros • そんなに悪いことしていない(はず) • フレームワーク越しでも使える
👎 Cons • IFがインターフェースじゃないと難しい • contextに直接詰められているわけではない ◦ http.ResponseWriterなどをビジネスロジックまで 引き回すことはあまりない(?) デコレータパターンで伝播する
© LayerX Inc. 21 • 親が参照しているオブジェクトのフィールドを⼦で編集する contextオブジェクトに構造体ポインタ(アドレス)を詰める
© LayerX Inc. 22 contextオブジェクトにポインタ構造体を詰める
© LayerX Inc. 23 contextオブジェクトにポインタ構造体を詰める ポインタの先にある構造体フィールドは⼦から編集できる
© LayerX Inc. 24 👍 Pros • メソッドシグネチャに影響せず、透過的に使える 👎 Cons
• 多⽤すると無法地帯になる ◦ 親からするとどのタイミングで詰め込まれたのかわからない • ⾮同期処理が絡むならMutexなどの検討が必要 contextオブジェクトにポインタ構造体を詰める
© LayerX Inc. 25 親コンテキストにどうしても情報を詰めたいとき • デコレータパターンで伝播する • contextオブジェクトにポインタ構造体を詰める ⚠
⽤法⽤量を守って正しくお使いください(親に渡すのは最終⼿段!) まとめ