// New creates an instance of Echo. func New() (e *Echo) { e = &Echo{maxParam: new(int)} e.pool.New = func() interface{} { return NewContext(nil, new(Response), e) } e.router = NewRouter(e) //---------- // Defaults //---------- e.HTTP2(true) e.defaultHTTPErrorHandler = func(err error, c *Context) { code := http.StatusInternalServerError msg := http.StatusText(code) if he, ok := err.(*HTTPError); ok { code = he.code msg = he.message } if e.debug { msg = err.Error() } if !c.response.committed { http.Error(c.response, msg, code) } e.logger.Error(err) } e.SetHTTPErrorHandler(e.defaultHTTPErrorHandler) e.SetBinder(&binder{}) // Logger e.logger = log.New("echo") e.logger.SetLevel(log.INFO) // @ modified by henrylee2cn 2016.1.22 e.blackfile = map[string]bool{ ".html": true, } return }
//---------------- // Error handlers //---------------- notFoundHandler = func(c *Context) error { return NewHTTPError(http.StatusNotFound) } methodNotAllowedHandler = func(c *Context) error { return NewHTTPError(http.StatusMethodNotAllowed) } unixEpochTime = time.Unix(0, 0) // @ modified by henrylee2cn 2016.1.22 Log = log.New("echo").SetLevel(log.INFO) ) // @ modified by henrylee2cn 2016.1.22 // New creates an instance of Echo. func New() (e *Echo) { e = &Echo{ maxParam: new(int), http2: true, logger: Log, binder: &binder{}, fileSystem: new(FileSystem), blackfile: map[string]bool{ ".html": true, }, defaultHTTPErrorHandler: func(err error, c *Context) {