server-go/web/fasthttp/servlet.go

56 lines
1.1 KiB
Go
Raw Permalink Normal View History

2018-08-22 08:37:12 +00:00
package fasthttp
import (
"strings"
"git.loafle.net/overflow/server-go"
"git.loafle.net/overflow/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)
}