From 34172d8cd07c1e431ae37a24a0ab1124efbfab50 Mon Sep 17 00:00:00 2001 From: hansongyu <359859461@qq.com> Date: Sat, 7 May 2022 16:08:45 +0800 Subject: [PATCH] Update routergroup.go --- routergroup.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/routergroup.go b/routergroup.go index 3fba3a91..bcd82cdb 100644 --- a/routergroup.go +++ b/routergroup.go @@ -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.