Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
9d0ab3c0f2 |
36
resource.go
36
resource.go
@@ -102,10 +102,38 @@ func (res *Resource) Delete(h http.HandlerFunc) {
|
|||||||
res.handlerFunc(http.MethodDelete, p, h)
|
res.handlerFunc(http.MethodDelete, p, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (res *Resource) Handle(pattern string, h http.HandlerFunc) {
|
// HandleGET on /group-pattern/:id/pattern
|
||||||
p := suffixIt(res.pattern, "{id}")
|
func (res *Resource) HandleGET(pattern string, h http.HandlerFunc) {
|
||||||
res.routes.Add(http.MethodDelete + " " + p)
|
res.handle(http.MethodGet, pattern, h)
|
||||||
res.handlerFunc(http.MethodDelete, p, h)
|
}
|
||||||
|
|
||||||
|
// HandlePOST on /group-pattern/:id/pattern
|
||||||
|
func (res *Resource) HandlePOST(pattern string, h http.HandlerFunc) {
|
||||||
|
res.handle(http.MethodPost, pattern, h)
|
||||||
|
}
|
||||||
|
|
||||||
|
// HandlePUT on /group-pattern/:id/pattern
|
||||||
|
func (res *Resource) HandlePUT(pattern string, h http.HandlerFunc) {
|
||||||
|
res.handle(http.MethodPut, pattern, h)
|
||||||
|
}
|
||||||
|
|
||||||
|
// HandlePATCH on /group-pattern/:id/pattern
|
||||||
|
func (res *Resource) HandlePATCH(pattern string, h http.HandlerFunc) {
|
||||||
|
res.handle(http.MethodPatch, pattern, h)
|
||||||
|
}
|
||||||
|
|
||||||
|
// HandleDELETE on /group-pattern/:id/pattern
|
||||||
|
func (res *Resource) HandleDELETE(pattern string, h http.HandlerFunc) {
|
||||||
|
res.handle(http.MethodDelete, pattern, h)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (res *Resource) handle(method string, pattern string, h http.HandlerFunc) {
|
||||||
|
if !strings.HasPrefix(pattern, "/") {
|
||||||
|
pattern = "/" + pattern
|
||||||
|
}
|
||||||
|
p := suffixIt(res.pattern, "{id}"+pattern)
|
||||||
|
res.routes.Add(method + " " + p)
|
||||||
|
res.handlerFunc(method, p, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
// handlerFunc registers the handler function for the given pattern.
|
// handlerFunc registers the handler function for the given pattern.
|
||||||
|
Reference in New Issue
Block a user