proposal: use Go 1.27 generic methods for typed Context helpers (PathParam/QueryParam/FormParam/Bind)
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 32.7k
- Forks
- 2.7k
- Avg merge
- 9h 35m
- Merged PRs (30d)
- 6
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.
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.
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.
Assessment
- Tech stack
- go
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100