Files
Gogs/internal/context/user.go
copilot-swe-agent[bot] da641a81f0 Continue Flamego migration: Update context files and fix compilation errors
- Fix Context struct with FlashData
- Add SetCookie, GetCookie, Tr helper methods
- Update user.go, go_get.go, org.go, repo.go context files
- Fix JSON, HTML rendering methods
- Update Contexter middleware to handle Flash properly
- Fix auth.go references to Request

Co-authored-by: unknwon <2946214+unknwon@users.noreply.github.com>
2026-01-25 12:02:00 +00:00

26 lines
678 B
Go

package context
import (
"github.com/flamego/flamego"
"gogs.io/gogs/internal/database"
)
// ParamsUser is the wrapper type of the target user defined by URL parameter, namely '<username>'.
type ParamsUser struct {
*database.User
}
// InjectParamsUser returns a handler that retrieves target user based on URL parameter '<username>',
// and injects it as *ParamsUser.
func InjectParamsUser() flamego.Handler {
return func(c *Context) {
user, err := database.Handle.Users().GetByUsername(c.Request.Context(), c.Param("username"))
if err != nil {
c.NotFoundOrError(err, "get user by name")
return
}
c.Context.MapTo(&ParamsUser{user}, (*ParamsUser)(nil))
}
}