func NewConfig(c *engine.Config) (s *Server) { s = &Server{ Server: new(http.Server), config: c, pool: &Pool{ request: sync.Pool{ New: func() interface{} { return &Request{} }, }, response: sync.Pool{ New: func() interface{} { return &Response{logger: s.logger} }, }, header: sync.Pool{ New: func() interface{} { return &Header{} }, }, url: sync.Pool{ New: func() interface{} { return &URL{} }, }, }, handler: engine.HandlerFunc(func(req engine.Request, res engine.Response) { s.logger.Fatal("handler not set") }), logger: log.New("echo"), } return }
// TODO: Fix me func TestServer(t *testing.T) { s := New("") s.SetHandler(engine.HandlerFunc(func(req engine.Request, res engine.Response) { })) ctx := new(fasthttp.RequestCtx) s.ServeHTTP(ctx) }
// NewFromConfig returns an instance of `standard.Server` from config. func NewFromConfig(c engine.Config) (s *Server) { s = &Server{ Server: new(http.Server), config: c, pool: &pool{ request: sync.Pool{ New: func() interface{} { return &Request{logger: s.logger} }, }, response: sync.Pool{ New: func() interface{} { return &Response{logger: s.logger} }, }, header: sync.Pool{ New: func() interface{} { return &Header{} }, }, url: sync.Pool{ New: func() interface{} { return &URL{} }, }, }, handler: engine.HandlerFunc(func(rq engine.Request, rs engine.Response) { s.logger.Error("handler not set, use `SetHandler()` to set it.") }), logger: log.New("echo"), } s.Addr = c.Address s.Handler = s return }
// TODO: Fix me func TestServer(t *testing.T) { s := New("") s.SetHandler(engine.HandlerFunc(func(req engine.Request, res engine.Response) { })) rec := httptest.NewRecorder() req := new(http.Request) s.ServeHTTP(rec, req) }
// WithConfig returns `Server` instance with provided config. func WithConfig(c engine.Config) (s *Server) { s = &Server{ Server: new(http.Server), config: c, pool: &pool{ request: sync.Pool{ New: func() interface{} { return &Request{logger: s.logger} }, }, response: sync.Pool{ New: func() interface{} { return &Response{logger: s.logger} }, }, responseAdapter: sync.Pool{ New: func() interface{} { return &responseAdapter{} }, }, header: sync.Pool{ New: func() interface{} { return &Header{} }, }, url: sync.Pool{ New: func() interface{} { return &URL{} }, }, }, handler: engine.HandlerFunc(func(req engine.Request, res engine.Response) { panic("echo: handler not set, use `Server#SetHandler()` to set it.") }), logger: glog.New("echo"), } s.ReadTimeout = c.ReadTimeout s.WriteTimeout = c.WriteTimeout s.Addr = c.Address s.Handler = s return }
// WithConfig returns `Server` with provided config. func WithConfig(c engine.Config) (s *Server) { s = &Server{ Server: new(fasthttp.Server), config: c, pool: &pool{ request: sync.Pool{ New: func() interface{} { return &Request{logger: s.logger} }, }, response: sync.Pool{ New: func() interface{} { return &Response{logger: s.logger} }, }, requestHeader: sync.Pool{ New: func() interface{} { return &RequestHeader{} }, }, responseHeader: sync.Pool{ New: func() interface{} { return &ResponseHeader{} }, }, url: sync.Pool{ New: func() interface{} { return &URL{} }, }, }, handler: engine.HandlerFunc(func(req engine.Request, res engine.Response) { s.logger.Error("handler not set, use `SetHandler()` to set it.") }), logger: glog.New("echo"), } s.ReadTimeout = c.ReadTimeout s.WriteTimeout = c.WriteTimeout s.Handler = s.ServeHTTP return }