1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-24 20:14:31 +02:00

New API Echo.Server

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Merten van Gerven 2015-06-27 23:34:22 +02:00 committed by Vishal Rana
parent b85f9dd147
commit 07c0cf21f0
3 changed files with 20 additions and 8 deletions

20
echo.go
View File

@ -153,7 +153,7 @@ func New() (e *Echo) {
// Defaults // Defaults
//---------- //----------
e.HTTP2(true) e.HTTP2(false)
e.notFoundHandler = func(c *Context) error { e.notFoundHandler = func(c *Context) error {
return NewHTTPError(http.StatusNotFound) return NewHTTPError(http.StatusNotFound)
} }
@ -423,15 +423,25 @@ func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
e.pool.Put(c) e.pool.Put(c)
} }
// Server returns the internal *http.Server
func (e *Echo) Server(addr string) *http.Server {
s := &http.Server{Addr: addr}
s.Handler = e
if e.http2 {
http2.ConfigureServer(s, nil)
}
return s
}
// Run runs a server. // Run runs a server.
func (e *Echo) Run(addr string) { func (e *Echo) Run(addr string) {
s := &http.Server{Addr: addr} s := e.Server(addr)
e.run(s) e.run(s)
} }
// RunTLS runs a server with TLS configuration. // RunTLS runs a server with TLS configuration.
func (e *Echo) RunTLS(addr, certFile, keyFile string) { func (e *Echo) RunTLS(addr, certFile, keyFile string) {
s := &http.Server{Addr: addr} s := e.Server(addr)
e.run(s, certFile, keyFile) e.run(s, certFile, keyFile)
} }
@ -446,10 +456,6 @@ func (e *Echo) RunTLSServer(srv *http.Server, certFile, keyFile string) {
} }
func (e *Echo) run(s *http.Server, files ...string) { func (e *Echo) run(s *http.Server, files ...string) {
s.Handler = e
if e.http2 {
http2.ConfigureServer(s, nil)
}
if len(files) == 0 { if len(files) == 0 {
log.Fatal(s.ListenAndServe()) log.Fatal(s.ListenAndServe())
} else if len(files) == 2 { } else if len(files) == 2 {

View File

@ -375,6 +375,12 @@ func TestEchoHTTPError(t *testing.T) {
assert.Equal(t, m, he.Error()) assert.Equal(t, m, he.Error())
} }
func TestEchoServer(t *testing.T) {
e := New()
s := e.Server(":1323")
assert.IsType(t, &http.Server{}, s)
}
func testMethod(t *testing.T, method, path string, e *Echo) { func testMethod(t *testing.T, method, path string, e *Echo) {
m := fmt.Sprintf("%c%s", method[0], strings.ToLower(method[1:])) m := fmt.Sprintf("%c%s", method[0], strings.ToLower(method[1:]))
p := reflect.ValueOf(path) p := reflect.ValueOf(path)

View File

@ -38,7 +38,7 @@ Echo is a fast HTTP router (zero dynamic memory allocation) and micro web framew
## Performance ## Performance
![Performance](http://i.imgur.com/dTBFmte.png) <iframe width="600" height="371" seamless frameborder="0" scrolling="no" src="https://docs.google.com/spreadsheets/d/1phsG_NPmEOaTVTw6lasK3CeEwBlbkhzAWPiyrBznm1g/pubchart?oid=178095723&amp;format=interactive"></iframe>
## Getting Started ## Getting Started