ing
This commit is contained in:
parent
6bf0de295a
commit
f5f96c0292
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user