server-go/web/fasthttp/servlet.go
crusader f5f96c0292 ing
2018-04-10 23:13:24 +09:00

56 lines
1.1 KiB
Go

package fasthttp
import (
"strings"
"git.loafle.net/commons/server-go"
"git.loafle.net/commons/server-go/web"
"github.com/valyala/fasthttp"
)
type Servlet interface {
web.Servlet
Handle(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx) *web.Error
RequestPath(ctx *fasthttp.RequestCtx) string
setContextPath(contextPath string)
}
type Servlets struct {
Servlet
ContextPath string
}
func (s *Servlets) ServletCtx(serverCtx server.ServerCtx) server.ServletCtx {
return server.NewServletContext(nil, serverCtx)
}
func (s *Servlets) Init(serverCtx server.ServerCtx) error {
return nil
}
func (s *Servlets) OnStart(serverCtx server.ServerCtx) error {
return nil
}
func (s *Servlets) OnStop(serverCtx server.ServerCtx) {
//
}
func (s *Servlets) Destroy(serverCtx server.ServerCtx) {
//
}
func (s *Servlets) Handle(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx) *web.Error {
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)
}