mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-07-08 10:00:03 +02:00
refactor bind functions based on generics (#22055)
This commit is contained in:
parent
003b4e209c
commit
6398ca745a
4 changed files with 168 additions and 188 deletions
|
@ -6,7 +6,6 @@ package private
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
|
@ -39,13 +38,9 @@ func CheckInternalToken(next http.Handler) http.Handler {
|
|||
}
|
||||
|
||||
// bind binding an obj to a handler
|
||||
func bind(obj interface{}) http.HandlerFunc {
|
||||
tp := reflect.TypeOf(obj)
|
||||
for tp.Kind() == reflect.Ptr {
|
||||
tp = tp.Elem()
|
||||
}
|
||||
func bind[T any](obj T) http.HandlerFunc {
|
||||
return web.Wrap(func(ctx *context.PrivateContext) {
|
||||
theObj := reflect.New(tp).Interface() // create a new form obj for every request but not use obj directly
|
||||
theObj := new(T) // create a new form obj for every request but not use obj directly
|
||||
binding.Bind(ctx.Req, theObj)
|
||||
web.SetForm(ctx, theObj)
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue