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
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
自動生成されたhttpエンドポイントごとにカスタムミドルウェアを挿入したい話
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
uhzz
June 07, 2024
Technology
3k
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
970
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
2026/09/10 Spring_Bootから_Jakarta_EE_MicroProfileへの移行
megascus
0
270
Bet AI Day 2026丨AIを「使う」から、AIが「働く」へ ― LayerXが進める「組織AI」の社会実装
layerx
PRO
3
2.9k
AI活用の現在地、 ちゃんと見えてますか?/XPfest-2026
visional_engineering_and_design
0
170
module Synths; end
asonas
1
130
「重なり」は迎える側がつくる ― 人もAIエージェントも歓迎するプロダクトエンジニアリング ―
go0517go
PRO
0
270
AI-DLCって実際どう? 〜聞きたいこと全部聞いてみる〜
news_it_enj
0
250
ASTを使って影響範囲を特定する
nealle
0
130
DEFCON_CHV_CTF_Write-up.pdf
bata_24
0
110
プロダクトエンジニアに必要な「いい感じ」に作る能力 〜たくさん作れる時代に、どこまで作るかの決め方〜
jnishime_dresscode
2
1.4k
[DroidKaigi 2026] Making UI specifications visible: Android UI development in the AI agent era supported by Compose Screenshot Testing and galleries
syarihu
0
610
From Vanilla Kubernetes to a Batteries-Included Platform: Developer Experience at 1,300+ Clusters
yosshi_
0
650
AI時代に、プロダクトの数だけ積み上がる所有コストをどうエンジニアリングするか / Engineering the Cost of Ownership
kzkmaeda
1
1.1k
Featured
See All Featured
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
690
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
Agile that works and the tools we love
rasmusluckow
331
22k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
290
Amusing Abliteration
ianozsvald
1
290
Balancing Empowerment & Direction
lara
6
1.3k
[RailsConf 2023] Rails as a piece of cake
palkan
59
7k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
730
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
4.7k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
470
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