diff --git a/web/fasthttp/server-handler.go b/web/fasthttp/server-handler.go index 8cbc74b..aee1f42 100644 --- a/web/fasthttp/server-handler.go +++ b/web/fasthttp/server-handler.go @@ -99,7 +99,7 @@ func (sh *ServerHandlers) RegisterServlet(contextPath string, servlet Servlet) { if nil == sh.servlets { sh.servlets = make(map[string]Servlet) } - servlet.(*Servlets).ContextPath = contextPath + servlet.setContextPath(contextPath) sh.servlets[contextPath] = servlet } diff --git a/web/fasthttp/servlet.go b/web/fasthttp/servlet.go index 15ff414..d227edf 100644 --- a/web/fasthttp/servlet.go +++ b/web/fasthttp/servlet.go @@ -13,6 +13,7 @@ type Servlet interface { Handle(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx) *web.Error RequestPath(ctx *fasthttp.RequestCtx) string + setContextPath(contextPath string) } type Servlets struct { @@ -45,6 +46,10 @@ func (s *Servlets) Handle(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx return nil } +func (s *Servlets) setContextPath(contextPath string) { + s.ContextPath = contextPath +} + func (s *Servlets) RequestPath(ctx *fasthttp.RequestCtx) string { return strings.Replace(string(ctx.Path()), s.ContextPath, "", -1) }