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エンドポイントごとにカスタムミドルウェアを挿入したい話
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
uhzz
June 07, 2024
Technology
3.1k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
自動生成されたhttpエンドポイントごとにカスタムミドルウェアを挿入したい話
https://gocon.jp/2024/sessions/21/
uhzz
June 07, 2024
More Decks by uhzz
See All by uhzz
DI コンテナ自動生成ツールを実装してみた / intro-autodi
uhzz
0
990
Goで実現するGraceful Shutdown ~実運用での課題と解決策~ / Go Conference 2025
uhzz
2
2k
MCP調べてみました! / Exploring MCP
uhzz
2
4.2k
Enablement Bootcampを終えて -Enablement Bootcamp for Gopherizing 〜業務で使えるGoを学ぼう〜
uhzz
0
370
安全にQAを行える環境が整いました!- Kyash TechTalk #6 - Kyashの開発をチラ見せ
uhzz
0
900
Goのローカル開発をWorkspacesではじめよう
uhzz
1
1.2k
【Go:パッケージ管理】DepからGo Modulesへ
uhzz
0
1.2k
コードレビューで泣かないためのintSize = 32 << (^uint(0) >> 63)
uhzz
0
280
「ウチも、gRPC使えますか?」
uhzz
0
360
Other Decks in Technology
See All in Technology
自分で立ててみるLLMサービス
y_sera15
0
140
Snapshot Testing in Practice: Predictable and Reliable SwiftUI Views
fespinoza
0
140
脆弱性診断って、何をしているの? 〜弱点を見つけて、会社の改善につなげるまで〜
keeg
0
490
Deep Data Security 機能解説
oracle4engineer
PRO
2
720
UniFi(ユニファイ)AIカメラの現場活用
ludicmind
1
180
ログラスのマルチプロダクトを 支える認証基盤 〜テナントごとに異なる統制とどう向き合うか〜
dada4386
3
410
オンラインゲームのシステム全体像 - コロプラ 2026年度 新卒研修
colopl
0
890
DevelopersIO 2026 知識の地図を描く ─ オントロジーとは何か?
ishikawa_satoru
1
220
オブザーバビリティを高める AI エージェント体験を考える / Designing AI Agent Experiences That Enhance Observability
aoto
PRO
2
310
生成AIと進める探索的データ分析(2026.10.03 第122回Tokyo.R勉強会)
tatamiya
2
1.4k
AIに攻撃される前に、AIに攻撃させる
tsuchikazu
0
160
データ品質を壊しながらSnowflakeのAIに分析させてみた
kawanago
0
530
Featured
See All Featured
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
320
Testing 201, or: Great Expectations
jmmastey
46
8.3k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
WENDY [Excerpt]
tessaabrams
14
40k
Fantastic passwords and where to find them - at NoRuKo
philnash
53
4k
A designer walks into a library…
pauljervisheath
211
25k
How to Ace a Technical Interview
jacobian
280
24k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
490
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
4
4.3k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.4k
Transcript
© 2024 Finatext Holdings Ltd. 自動生成されたhttpエンドポイントごとに カスタムミドルウェアを挿入したい話 Go Conference 2024
reo(@_uhzz_)
© 2024 Finatext Holdings Ltd. 自己紹介 1 X:@_uhzz_ GitHub:uh-zz Goとサウナが好きです
Reo Uehara / 株式会社Finatext
© 2024 Finatext Holdings Ltd. • 前提 • oapi-codegen の紹介
• issueで報告されているミドルウェア周りの話 • 独自の解決案を紹介 • まとめ アジェンダ 2
© 2024 Finatext Holdings Ltd. 前提 ルーティングエンジンは、弊社証券サービスで利用しているEchoを対象にします 3 https://techblog.finatext.com/technology-stack-for-reinventing-finance-as-a-service-4c76ea5ee6fc
© 2024 Finatext Holdings Ltd. 4 oapi-codegen の紹介
© 2024 Finatext Holdings Ltd. oapi-codegen の紹介 OpenAPI定義からGoコードを生成するツールです 5 コード生成
https://github.com/deepmap/oapi-codegen
© 2024 Finatext Holdings Ltd. oapi-codegen の紹介 インタフェースに沿って実装するだけ! ルーティングはoapi-codegenが生成したコード側で、設定してくれる 6
インタフェースに沿ったサーバの実装を定義 生成されたルーティング関数に渡します
© 2024 Finatext Holdings Ltd. 7 issueで報告されているミドルウェア周りの話
© 2024 Finatext Holdings Ltd. issueで報告されているミドルウェア周りの話 エンドポイントごとにミドルウェアを差し込めない 上記の関数はルーティングのために生成されたボイラープレートコード 現状、エンドポイント毎にミドルウェアを渡す仕組みが用意されていない 8
© 2024 Finatext Holdings Ltd. 9 独自の解決案を紹介
© 2024 Finatext Holdings Ltd. 独自の解決案を紹介 解決したかった問題 10 やりたかったこと: 認証したあと、個別のエンドポイントに対して
ミドルウェア処理を行いたい 課題: 認証ミドルウェアは個別に設定可能 →ただし認証以外のミドルウェアを個別に設定 する機構がない
© 2024 Finatext Holdings Ltd. 独自の解決案を紹介 このように解決した (OpenAPI→Goコード生成) 11 アプローチ:
スキーマ駆動の精神で、OpenAPI側で制御 具体的には、APIごとにタグ付けを行う ポイント: 生成されるボイラープレートコードの echo.Contextにタグ情報をセットしている
© 2024 Finatext Holdings Ltd. 独自の解決案を紹介 このように解決した (Goアプリケーション側) 12 アプローチ:
独自のContextで、echo.Contextをラップ ポイント: echo.Contextにセットされたタグの取得と、 ミドルウェア呼び出しを独自Contextでラップ することで、コードの再利用性が向上します
© 2024 Finatext Holdings Ltd. 独自の解決案を紹介 このように解決した (Goアプリケーション側) 13 アプローチ:
独自のContextで、echo.Contextをラップ ポイント: echo.Contextにセットされたタグの取得と、 ミドルウェア呼び出しを独自Contextでラップ することで、コードの再利用性が向上します
© 2024 Finatext Holdings Ltd. 独自の解決案を紹介 14 このように解決した (独自のContext実装例) https://codehex.hateblo.jp/entry/echo-context
を参考に実装
© 2024 Finatext Holdings Ltd. • oapi-codegenを使うと、 OpenAPI 準拠の REST
API サーバを 生成することが可能 • 現状、生成されたエンドポイントごとに、カスタムミドルウェアを 割り当てられない問題がある ◦ issueで報告されている ◦ メンテナも反応しているのでサポートされるかも • ミドルウェア相当の処理を各エンドポイントで実行する方法を紹介 まとめ 15 詳細な実装サンプルはブログを書くので、ぜひフォローしてね👍
None