This commit is contained in:
crusader 2018-04-10 23:13:24 +09:00
parent 6bf0de295a
commit f5f96c0292
2 changed files with 6 additions and 1 deletions

View File

@ -99,7 +99,7 @@ func (sh *ServerHandlers) RegisterServlet(contextPath string, servlet Servlet) {
if nil == sh.servlets { if nil == sh.servlets {
sh.servlets = make(map[string]Servlet) sh.servlets = make(map[string]Servlet)
} }
servlet.(*Servlets).ContextPath = contextPath servlet.setContextPath(contextPath)
sh.servlets[contextPath] = servlet sh.servlets[contextPath] = servlet
} }

View File

@ -13,6 +13,7 @@ type Servlet interface {
Handle(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx) *web.Error Handle(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx) *web.Error
RequestPath(ctx *fasthttp.RequestCtx) string RequestPath(ctx *fasthttp.RequestCtx) string
setContextPath(contextPath string)
} }
type Servlets struct { type Servlets struct {
@ -45,6 +46,10 @@ func (s *Servlets) Handle(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx
return nil return nil
} }
func (s *Servlets) setContextPath(contextPath string) {
s.ContextPath = contextPath
}
func (s *Servlets) RequestPath(ctx *fasthttp.RequestCtx) string { func (s *Servlets) RequestPath(ctx *fasthttp.RequestCtx) string {
return strings.Replace(string(ctx.Path()), s.ContextPath, "", -1) return strings.Replace(string(ctx.Path()), s.ContextPath, "", -1)
} }