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:
parent
b85f9dd147
commit
07c0cf21f0
20
echo.go
20
echo.go
@ -153,7 +153,7 @@ func New() (e *Echo) {
|
||||
// Defaults
|
||||
//----------
|
||||
|
||||
e.HTTP2(true)
|
||||
e.HTTP2(false)
|
||||
e.notFoundHandler = func(c *Context) error {
|
||||
return NewHTTPError(http.StatusNotFound)
|
||||
}
|
||||
@ -423,15 +423,25 @@ func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
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.
|
||||
func (e *Echo) Run(addr string) {
|
||||
s := &http.Server{Addr: addr}
|
||||
s := e.Server(addr)
|
||||
e.run(s)
|
||||
}
|
||||
|
||||
// RunTLS runs a server with TLS configuration.
|
||||
func (e *Echo) RunTLS(addr, certFile, keyFile string) {
|
||||
s := &http.Server{Addr: addr}
|
||||
s := e.Server(addr)
|
||||
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) {
|
||||
s.Handler = e
|
||||
if e.http2 {
|
||||
http2.ConfigureServer(s, nil)
|
||||
}
|
||||
if len(files) == 0 {
|
||||
log.Fatal(s.ListenAndServe())
|
||||
} else if len(files) == 2 {
|
||||
|
@ -375,6 +375,12 @@ func TestEchoHTTPError(t *testing.T) {
|
||||
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) {
|
||||
m := fmt.Sprintf("%c%s", method[0], strings.ToLower(method[1:]))
|
||||
p := reflect.ValueOf(path)
|
||||
|
@ -38,7 +38,7 @@ Echo is a fast HTTP router (zero dynamic memory allocation) and micro web framew
|
||||
|
||||
## 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&format=interactive"></iframe>
|
||||
|
||||
## Getting Started
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user