1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-24 20:14:31 +02:00
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2016-08-18 11:27:37 -07:00
parent 7fa42ab978
commit 18b9e23ace
6 changed files with 27 additions and 17 deletions

View File

@ -230,7 +230,7 @@ func New() (e *Echo) {
e.SetHTTPErrorHandler(e.DefaultHTTPErrorHandler)
e.SetBinder(&binder{})
l := glog.New("echo")
l.SetLevel(glog.ERROR)
l.SetLevel(glog.OFF)
e.SetLogger(l)
return
}
@ -576,7 +576,9 @@ func (e *Echo) Run(s engine.Server) {
e.SetLogLevel(glog.DEBUG)
e.logger.Debug("running in debug mode")
}
e.logger.Error(s.Start())
if err := s.Start(); err != nil {
panic(fmt.Sprintf("echo: %v", err))
}
}
// NewHTTPError creates a new HTTPError instance.

View File

@ -80,7 +80,7 @@ func WithConfig(c engine.Config) (s *Server) {
},
},
handler: engine.HandlerFunc(func(req engine.Request, res engine.Response) {
s.logger.Error("handler not set, use `SetHandler()` to set it.")
panic("echo: handler not set, use `Server#SetHandler()` to set it.")
}),
logger: glog.New("echo"),
}

View File

@ -1,6 +1,7 @@
package standard
import (
"fmt"
"io"
"io/ioutil"
"mime/multipart"
@ -151,11 +152,11 @@ func (r *Request) FormValue(name string) string {
func (r *Request) FormParams() map[string][]string {
if strings.HasPrefix(r.header.Get(echo.HeaderContentType), echo.MIMEMultipartForm) {
if err := r.ParseMultipartForm(defaultMemory); err != nil {
r.logger.Error(err)
panic(fmt.Sprintf("echo: %v", err))
}
} else {
if err := r.ParseForm(); err != nil {
r.logger.Error(err)
panic(fmt.Sprintf("echo: %v", err))
}
}
return map[string][]string(r.Request.Form)

View File

@ -78,7 +78,7 @@ func WithConfig(c engine.Config) (s *Server) {
},
},
handler: engine.HandlerFunc(func(req engine.Request, res engine.Response) {
s.logger.Error("handler not set, use `SetHandler()` to set it.")
panic("echo: handler not set, use `Server#SetHandler()` to set it.")
}),
logger: glog.New("echo"),
}

View File

@ -54,7 +54,7 @@ func NewRouter(e *Echo) *Router {
func (r *Router) Add(method, path string, h HandlerFunc, e *Echo) {
// Validate path
if path == "" {
e.logger.Fatal("path cannot be empty")
panic("echo: path cannot be empty")
}
if path[0] != '/' {
path = "/" + path

View File

@ -66,7 +66,7 @@ func NewConfig(c *engine.Config) (s *Server) {
},
},
handler: engine.HandlerFunc(func(req engine.Request, res engine.Response) {
s.logger.Fatal("handler not set")
panic("echo: handler not set, use `Server#SetHandler()` to set it.")
}),
logger: log.New("echo"),
}
@ -81,16 +81,23 @@ func (s *Server) SetLogger(l *log.Logger) {
s.logger = l
}
func (s *Server) Start() {
s.Addr = s.config.Address
s.Handler = s
certFile := s.config.TLSCertFile
keyFile := s.config.TLSKeyFile
if certFile != "" && keyFile != "" {
s.logger.Fatal(s.ListenAndServeTLS(certFile, keyFile))
} else {
s.logger.Fatal(s.ListenAndServe())
func (s *Server) Start() error {
if s.config.Listener == nil {
return s.startDefaultListener()
}
return s.startCustomListener()
}
func (s *Server) startDefaultListener() error {
c := s.config
if c.TLSCertFile != "" && c.TLSKeyFile != "" {
return s.ListenAndServeTLS(c.TLSCertFile, c.TLSKeyFile)
}
return s.ListenAndServe()
}
func (s *Server) startCustomListener() error {
return s.Serve(s.config.Listener)
}
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {