added default hook handler arg name and router search helper
This commit is contained in:
parent
3e0869a30b
commit
ff3f4332ce
|
@ -108,7 +108,7 @@ func (h *Hook[T]) Bind(handler *Handler[T]) string {
|
||||||
// The registered handler is added with a default 0 priority and the id will be autogenerated.
|
// The registered handler is added with a default 0 priority and the id will be autogenerated.
|
||||||
//
|
//
|
||||||
// If you want to register a handler with custom priority or id use the [Hook.Bind] method.
|
// If you want to register a handler with custom priority or id use the [Hook.Bind] method.
|
||||||
func (h *Hook[T]) BindFunc(fn func(T) error) string {
|
func (h *Hook[T]) BindFunc(fn func(e T) error) string {
|
||||||
return h.Bind(&Handler[T]{Func: fn})
|
return h.Bind(&Handler[T]{Func: fn})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ func (h *TaggedHook[T]) Bind(handler *Handler[T]) string {
|
||||||
//
|
//
|
||||||
// It is similar to [Hook.Bind] with the difference that the handler
|
// It is similar to [Hook.Bind] with the difference that the handler
|
||||||
// function is invoked only if the event data tags satisfy h.CanTriggerOn.
|
// function is invoked only if the event data tags satisfy h.CanTriggerOn.
|
||||||
func (h *TaggedHook[T]) BindFunc(fn func(T) error) string {
|
func (h *TaggedHook[T]) BindFunc(fn func(e T) error) string {
|
||||||
return h.mainHook.BindFunc(func(e T) error {
|
return h.mainHook.BindFunc(func(e T) error {
|
||||||
if h.CanTriggerOn(e.Tags()) {
|
if h.CanTriggerOn(e.Tags()) {
|
||||||
return fn(e)
|
return fn(e)
|
||||||
|
|
|
@ -137,6 +137,11 @@ func (group *RouterGroup[T]) GET(path string, action func(T) error) *Route[T] {
|
||||||
return group.Route(http.MethodGet, path, action)
|
return group.Route(http.MethodGet, path, action)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SEARCH is a shorthand for [Group.AddRoute] with SEARCH as route method.
|
||||||
|
func (group *RouterGroup[T]) SEARCH(path string, action func(T) error) *Route[T] {
|
||||||
|
return group.Route("SEARCH", path, action)
|
||||||
|
}
|
||||||
|
|
||||||
// POST is a shorthand for [Group.AddRoute] with POST as route method.
|
// POST is a shorthand for [Group.AddRoute] with POST as route method.
|
||||||
func (group *RouterGroup[T]) POST(path string, action func(T) error) *Route[T] {
|
func (group *RouterGroup[T]) POST(path string, action func(T) error) *Route[T] {
|
||||||
return group.Route(http.MethodPost, path, action)
|
return group.Route(http.MethodPost, path, action)
|
||||||
|
|
|
@ -260,6 +260,11 @@ func TestRouterGroupRouteAliases(t *testing.T) {
|
||||||
http.MethodGet,
|
http.MethodGet,
|
||||||
"/test",
|
"/test",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
group.SEARCH("/test", testAction),
|
||||||
|
"SEARCH",
|
||||||
|
"/test",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
group.POST("/test", testAction),
|
group.POST("/test", testAction),
|
||||||
http.MethodPost,
|
http.MethodPost,
|
||||||
|
|
Loading…
Reference in New Issue