proposal: use Go 1.27 generic methods for typed Context helpers (PathParam/QueryParam/FormParam/Bind)
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 35/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- go
調査の方向性
まず、既存の v4 の型付きヘルパーセットと v5 Context API を確認してください。ジェネリックメソッドに必要な Go の最小バージョンを確認し、提案された Context メソッドと既存のパッケージレベルのヘルパーをどのように共存させるべきかを決定してください。ヘルパーセット、互換性の動作、および Go バージョン要件について合意し、プロジェクトのテストでカバーできた時点で作業は完了です。
索引モデルが issue の本文から書いたものです。
説明
Go 1.27 has been released with support for generic methods (release notes, proposal golang/go#77273). This removes the language limitation mentioned in #2856 — "structs can not have generic methods, only generic functions are allowed" — that forced the typed helpers in v4 to be package-level functions like echo.PathParam[int](c, "id").
Now that v5's Context is a struct and the language supports it, the helpers can become real methods:
Before (v4 style):
id, err := echo.PathParam[int](c, "id")
page, err := echo.QueryParam[int](c, "page")
After (generic methods):
id, err := c.PathParam[int]("id")
page, err := c.QueryParam[int]("page")
Suggested additions (mirroring the v4 helper set):
func (c *Context) PathParam[T any](name string) (T, error)
func (c *Context) QueryParam[T any](name string) (T, error)
func (c *Context) FormParam[T any](name string) (T, error)
func (c *Context) PathParamOr[T any](name string, def T) (T, error)
func (c *Context) QueryParamOr[T any](name string, def T) (T, error)
func (c *Context) FormParamOr[T any](name string, def T) (T, error)
func (c *Context) QueryParams[T any](name string) ([]T, error)
func (c *Context) FormParams[T any](name string) ([]T, error)
Note: since Context is no longer an interface in v5, adding methods is not a breaking change for users — existing code calling c.PathParam("id") keeps compiling, and the existing package-level generic functions can be kept (or deprecated) as thin wrappers.
The only blocker is the minimum Go version: generic methods require go 1.27 in go.mod. Filing this now so it's on the radar for when Echo bumps its minimum supported Go version to 1.27.
- 主要言語
- Go
- スター
- 32.7k
- フォーク
- 2.8k
- 平均マージ
- 9時間 39分
- マージ済み PR(30日)
- 6
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
labstack/echo のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 74/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
似ている issue
-
bug github_actions
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
registrystack/registry-stack#1393 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
JakeChampion/lang#10213 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
oasisprotocol/oasis-sdk#2523 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100