2016-02-09 21:43:00 +02:00
|
|
|
// +build !appengine
|
|
|
|
|
2016-01-29 09:46:11 +02:00
|
|
|
package fasthttp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2016-02-05 00:40:08 +02:00
|
|
|
|
2016-01-29 09:46:11 +02:00
|
|
|
"github.com/labstack/echo/engine"
|
2016-02-05 05:29:49 +02:00
|
|
|
"github.com/labstack/echo/logger"
|
2016-01-29 09:46:11 +02:00
|
|
|
"github.com/valyala/fasthttp"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
Server struct {
|
|
|
|
*http.Server
|
|
|
|
config *engine.Config
|
|
|
|
handler engine.HandlerFunc
|
2016-02-05 05:29:49 +02:00
|
|
|
logger logger.Logger
|
2016-01-29 09:46:11 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2016-02-05 05:29:49 +02:00
|
|
|
func NewServer(c *engine.Config, h engine.HandlerFunc, l logger.Logger) *Server {
|
2016-01-29 09:46:11 +02:00
|
|
|
return &Server{
|
|
|
|
Server: new(http.Server),
|
2016-02-05 05:29:49 +02:00
|
|
|
config: c,
|
|
|
|
handler: h,
|
|
|
|
logger: l,
|
2016-01-29 09:46:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) Start() {
|
2016-02-09 08:17:20 +02:00
|
|
|
fasthttp.ListenAndServe(s.config.Address, func(c *fasthttp.RequestCtx) {
|
2016-01-29 09:46:11 +02:00
|
|
|
req := &Request{
|
2016-02-09 08:17:20 +02:00
|
|
|
context: c,
|
|
|
|
url: &URL{c.URI()},
|
|
|
|
header: &RequestHeader{c.Request.Header},
|
2016-01-29 09:46:11 +02:00
|
|
|
}
|
|
|
|
res := &Response{
|
2016-02-09 08:17:20 +02:00
|
|
|
context: c,
|
|
|
|
header: &ResponseHeader{c.Response.Header},
|
2016-01-29 09:46:11 +02:00
|
|
|
}
|
|
|
|
s.handler(req, res)
|
|
|
|
})
|
2016-02-05 05:29:49 +02:00
|
|
|
s.logger.Fatal(s.ListenAndServe())
|
2016-01-29 09:46:11 +02:00
|
|
|
}
|