[#5614] removed hook.HandlerFunc[T] type

This commit is contained in:
Gani Georgiev
2024-10-07 09:52:31 +03:00
parent 1d4dd5d5b4
commit 393b461ea2
13 changed files with 4236 additions and 4235 deletions
+10 -10
View File
@@ -46,7 +46,7 @@ func (group *RouterGroup[T]) Group(prefix string) *RouterGroup[T] {
//
// If you need to specify a named middleware (ex. so that it can be removed)
// or middleware with custom exec prirority, use [Group.Bind] method.
func (group *RouterGroup[T]) BindFunc(middlewareFuncs ...hook.HandlerFunc[T]) *RouterGroup[T] {
func (group *RouterGroup[T]) BindFunc(middlewareFuncs ...func(T) error) *RouterGroup[T] {
for _, m := range middlewareFuncs {
group.Middlewares = append(group.Middlewares, &hook.Handler[T]{Func: m})
}
@@ -115,7 +115,7 @@ func (group *RouterGroup[T]) Unbind(middlewareIds ...string) *RouterGroup[T] {
// meaning that only a top level group route could have HOST as part of the prefix.
//
// Returns the newly created route to allow attaching route-only middlewares.
func (group *RouterGroup[T]) Route(method string, path string, action hook.HandlerFunc[T]) *Route[T] {
func (group *RouterGroup[T]) Route(method string, path string, action func(T) error) *Route[T] {
route := &Route[T]{
Method: method,
Path: path,
@@ -128,42 +128,42 @@ func (group *RouterGroup[T]) Route(method string, path string, action hook.Handl
}
// Any is a shorthand for [Group.AddRoute] with "" as route method (aka. matches any method).
func (group *RouterGroup[T]) Any(path string, action hook.HandlerFunc[T]) *Route[T] {
func (group *RouterGroup[T]) Any(path string, action func(T) error) *Route[T] {
return group.Route("", path, action)
}
// GET is a shorthand for [Group.AddRoute] with GET as route method.
func (group *RouterGroup[T]) GET(path string, action hook.HandlerFunc[T]) *Route[T] {
func (group *RouterGroup[T]) GET(path string, action func(T) error) *Route[T] {
return group.Route(http.MethodGet, path, action)
}
// POST is a shorthand for [Group.AddRoute] with POST as route method.
func (group *RouterGroup[T]) POST(path string, action hook.HandlerFunc[T]) *Route[T] {
func (group *RouterGroup[T]) POST(path string, action func(T) error) *Route[T] {
return group.Route(http.MethodPost, path, action)
}
// DELETE is a shorthand for [Group.AddRoute] with DELETE as route method.
func (group *RouterGroup[T]) DELETE(path string, action hook.HandlerFunc[T]) *Route[T] {
func (group *RouterGroup[T]) DELETE(path string, action func(T) error) *Route[T] {
return group.Route(http.MethodDelete, path, action)
}
// PATCH is a shorthand for [Group.AddRoute] with PATCH as route method.
func (group *RouterGroup[T]) PATCH(path string, action hook.HandlerFunc[T]) *Route[T] {
func (group *RouterGroup[T]) PATCH(path string, action func(T) error) *Route[T] {
return group.Route(http.MethodPatch, path, action)
}
// PUT is a shorthand for [Group.AddRoute] with PUT as route method.
func (group *RouterGroup[T]) PUT(path string, action hook.HandlerFunc[T]) *Route[T] {
func (group *RouterGroup[T]) PUT(path string, action func(T) error) *Route[T] {
return group.Route(http.MethodPut, path, action)
}
// HEAD is a shorthand for [Group.AddRoute] with HEAD as route method.
func (group *RouterGroup[T]) HEAD(path string, action hook.HandlerFunc[T]) *Route[T] {
func (group *RouterGroup[T]) HEAD(path string, action func(T) error) *Route[T] {
return group.Route(http.MethodHead, path, action)
}
// OPTIONS is a shorthand for [Group.AddRoute] with OPTIONS as route method.
func (group *RouterGroup[T]) OPTIONS(path string, action hook.HandlerFunc[T]) *Route[T] {
func (group *RouterGroup[T]) OPTIONS(path string, action func(T) error) *Route[T] {
return group.Route(http.MethodOptions, path, action)
}
+2 -2
View File
@@ -5,7 +5,7 @@ import "github.com/pocketbase/pocketbase/tools/hook"
type Route[T hook.Resolver] struct {
excludedMiddlewares map[string]struct{}
Action hook.HandlerFunc[T]
Action func(T) error
Method string
Path string
Middlewares []*hook.Handler[T]
@@ -18,7 +18,7 @@ type Route[T hook.Resolver] struct {
//
// If you need to specify a named middleware (ex. so that it can be removed)
// or middleware with custom exec prirority, use the [Bind] method.
func (route *Route[T]) BindFunc(middlewareFuncs ...hook.HandlerFunc[T]) *Route[T] {
func (route *Route[T]) BindFunc(middlewareFuncs ...func(T) error) *Route[T] {
for _, m := range middlewareFuncs {
route.Middlewares = append(route.Middlewares, &hook.Handler[T]{Func: m})
}