1
0
mirror of https://github.com/labstack/echo.git synced 2025-01-10 00:28:23 +02:00
echo/engine/fasthttp/server.go
Vishal Rana 0731959a98 Object method to get real object
Signed-off-by: Vishal Rana <vr@labstack.com>
2016-02-08 16:48:03 -08:00

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())
}