server-go/web/fasthttp/servlet.go

51 lines
1023 B
Go
Raw Normal View History

2018-04-05 15:15:29 +00:00
package fasthttp
import (
2018-04-10 14:06:39 +00:00
"strings"
2018-04-05 15:15:29 +00:00
"git.loafle.net/commons/server-go"
"git.loafle.net/commons/server-go/web"
"github.com/valyala/fasthttp"
)
type Servlet interface {
web.Servlet
2018-04-06 05:50:20 +00:00
Handle(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx) *web.Error
2018-04-10 14:06:39 +00:00
RequestPath(ctx *fasthttp.RequestCtx) string
2018-04-05 15:15:29 +00:00
}
type Servlets struct {
Servlet
2018-04-10 14:06:39 +00:00
ContextPath string
2018-04-05 15:15:29 +00:00
}
func (s *Servlets) ServletCtx(serverCtx server.ServerCtx) server.ServletCtx {
return server.NewServletContext(nil, serverCtx)
}
func (s *Servlets) Init(serverCtx server.ServerCtx) error {
return nil
}
2018-04-09 12:48:14 +00:00
func (s *Servlets) OnStart(serverCtx server.ServerCtx) error {
return nil
}
func (s *Servlets) OnStop(serverCtx server.ServerCtx) {
//
}
2018-04-05 15:15:29 +00:00
func (s *Servlets) Destroy(serverCtx server.ServerCtx) {
//
}
2018-04-06 05:50:20 +00:00
func (s *Servlets) Handle(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx) *web.Error {
2018-04-06 04:06:05 +00:00
return nil
2018-04-05 15:15:29 +00:00
}
2018-04-10 14:06:39 +00:00
func (s *Servlets) RequestPath(ctx *fasthttp.RequestCtx) string {
return strings.Replace(string(ctx.Path()), s.ContextPath, "", -1)
}