proposal: use Go 1.27 generic methods for typed Context helpers (PathParam/QueryParam/FormParam/Bind)
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- go
- Domain
- backend-api-design
Research direction
Review the existing v4 typed helper set and the v5 Context API first. Confirm the minimum Go version needed for generic methods and determine how the proposed Context methods and existing package-level helpers should coexist. The work is done when the helper set, compatibility behavior, and Go version requirement are agreed and covered by the project’s tests.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Go
- Stars
- 32.7k
- Forks
- 2.8k
- Avg merge
- 9h 39m
- Merged PRs (30d)
- 6
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from labstack/echo
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Difficulty 3/5 1-2 days Newbie friendliness 74/100
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
Similar issues
-
kind/bug needs-triage
Difficulty 1/5 Under an hour Newbie friendliness 72/100
matrixorigin/matrixone#29223 ·
-
needs-acceptance wg/data-plane-networking
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vllm-project/semantic-router#4024 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
alexgorbatchev/dotfiles#107 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100