mirror of
https://github.com/labstack/echo.git
synced 2025-01-10 00:28:23 +02:00
0731959a98
Signed-off-by: Vishal Rana <vr@labstack.com>
44 lines
820 B
Go
44 lines
820 B
Go
package fasthttp
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/labstack/echo/engine"
|
|
"github.com/labstack/echo/logger"
|
|
"github.com/valyala/fasthttp"
|
|
)
|
|
|
|
type (
|
|
Server struct {
|
|
*http.Server
|
|
config *engine.Config
|
|
handler engine.HandlerFunc
|
|
logger logger.Logger
|
|
}
|
|
)
|
|
|
|
func NewServer(c *engine.Config, h engine.HandlerFunc, l logger.Logger) *Server {
|
|
return &Server{
|
|
Server: new(http.Server),
|
|
config: c,
|
|
handler: h,
|
|
logger: l,
|
|
}
|
|
}
|
|
|
|
func (s *Server) Start() {
|
|
fasthttp.ListenAndServe(s.config.Address, func(ctx *fasthttp.RequestCtx) {
|
|
req := &Request{
|
|
request: ctx,
|
|
url: &URL{ctx.URI()},
|
|
header: &RequestHeader{ctx.Request.Header},
|
|
}
|
|
res := &Response{
|
|
response: ctx,
|
|
header: &ResponseHeader{ctx.Response.Header},
|
|
}
|
|
s.handler(req, res)
|
|
})
|
|
s.logger.Fatal(s.ListenAndServe())
|
|
}
|