Update routergroup.go

This commit is contained in:
hansongyu 2022-05-07 16:08:45 +08:00 committed by GitHub
parent 90e7073d56
commit 34172d8cd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 0 deletions

View File

@ -89,6 +89,20 @@ func (group *RouterGroup) handle(httpMethod, relativePath string, handlers Handl
return group.returnObj()
}
func (group *RouterGroup) unhandle(httpMethod, relativePath string) IRoutes {
absolutePath := group.calculateAbsolutePath(relativePath)
group.engine.delRoute(httpMethod, absolutePath)
return group.returnObj()
}
// REMOVE is the way to delete route
func (group *RouterGroup) REMOVE(httpMethod,relativePath string) IRoutes {
if matched := regEnLetter.MatchString(httpMethod); !matched {
panic("http method " + httpMethod + " is not valid")
}
return group.unhandle(httpMethod, relativePath)
}
// Handle registers a new request handle and middleware with the given path and method.
// The last handler should be the real handler, the other ones should be middleware that can and should be shared among different routes.
// See the example code in GitHub.