This commit is contained in:
crusader 2018-04-10 23:06:39 +09:00
parent 40422f2d22
commit 6bf0de295a
2 changed files with 10 additions and 0 deletions

View File

@ -99,6 +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
sh.servlets[contextPath] = servlet sh.servlets[contextPath] = servlet
} }

View File

@ -1,6 +1,8 @@
package fasthttp package fasthttp
import ( import (
"strings"
"git.loafle.net/commons/server-go" "git.loafle.net/commons/server-go"
"git.loafle.net/commons/server-go/web" "git.loafle.net/commons/server-go/web"
"github.com/valyala/fasthttp" "github.com/valyala/fasthttp"
@ -10,10 +12,13 @@ type Servlet interface {
web.Servlet web.Servlet
Handle(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx) *web.Error Handle(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx) *web.Error
RequestPath(ctx *fasthttp.RequestCtx) string
} }
type Servlets struct { type Servlets struct {
Servlet Servlet
ContextPath string
} }
func (s *Servlets) ServletCtx(serverCtx server.ServerCtx) server.ServletCtx { func (s *Servlets) ServletCtx(serverCtx server.ServerCtx) server.ServletCtx {
@ -39,3 +44,7 @@ func (s *Servlets) Destroy(serverCtx server.ServerCtx) {
func (s *Servlets) Handle(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx) *web.Error { func (s *Servlets) Handle(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx) *web.Error {
return nil return nil
} }
func (s *Servlets) RequestPath(ctx *fasthttp.RequestCtx) string {
return strings.Replace(string(ctx.Path()), s.ContextPath, "", -1)
}