mirror of
https://github.com/gogs/gogs.git
synced 2026-02-01 12:09:26 +01:00
- 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>
26 lines
678 B
Go
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))
|
|
}
|
|
}
|