@@ -134,23 +134,23 @@ func New() (e *Echo) {
134134 // Defaults
135135 //----------
136136
137- e .MaxParam (5 )
137+ e .SetMaxParam (5 )
138138 e .notFoundHandler = func (c * Context ) * HTTPError {
139139 return & HTTPError {Code : http .StatusNotFound }
140140 }
141- e .HTTPErrorHandler (func (he * HTTPError , c * Context ) {
141+ e .SetHTTPErrorHandler (func (he * HTTPError , c * Context ) {
142142 if he .Code == 0 {
143143 he .Code = http .StatusInternalServerError
144144 }
145145 if he .Message == "" {
146146 he .Message = http .StatusText (he .Code )
147- if e . debug && he . Error != nil {
148- he . Message = he .Error . Error ()
149- }
147+ }
148+ if e . debug && he .Error != nil {
149+ he . Message = he . Error . Error ()
150150 }
151151 http .Error (c .Response , he .Message , he .Code )
152152 })
153- e .Binder (func (r * http.Request , v interface {}) * HTTPError {
153+ e .SetBinder (func (r * http.Request , v interface {}) * HTTPError {
154154 ct := r .Header .Get (ContentType )
155155 err := UnsupportedMediaType
156156 if strings .HasPrefix (ct , ApplicationJSON ) {
@@ -178,33 +178,37 @@ func (e *Echo) Group(pfx string, m ...Middleware) *Echo {
178178 return & g
179179}
180180
181- // MaxParam sets the maximum number of path parameters allowed for the application.
181+ // SetMaxParam sets the maximum number of path parameters allowed for the application.
182182// Default value is 5, good enough for many use cases.
183- func (e * Echo ) MaxParam (n uint8 ) {
183+ func (e * Echo ) SetMaxParam (n uint8 ) {
184184 e .maxParam = n
185185}
186186
187- // HTTPErrorHandler registers an HTTP error handler .
188- func (e * Echo ) HTTPErrorHandler (h HTTPErrorHandler ) {
187+ // SetHTTPErrorHandler registers an Echo.HTTPErrorHandler .
188+ func (e * Echo ) SetHTTPErrorHandler (h HTTPErrorHandler ) {
189189 e .httpErrorHandler = h
190190}
191191
192- // Binder registers a custom binder. It's invoked by Context.Bind API .
193- func (e * Echo ) Binder (b BindFunc ) {
192+ // SetBinder registers a custom binder. It's invoked by Context.Bind() .
193+ func (e * Echo ) SetBinder (b BindFunc ) {
194194 e .binder = b
195195}
196196
197- // Renderer registers an HTML template renderer. It's invoked by Context.Render
198- // API.
199- func (e * Echo ) Renderer (r Renderer ) {
197+ // SetRenderer registers an HTML template renderer. It's invoked by Context.Render().
198+ func (e * Echo ) SetRenderer (r Renderer ) {
200199 e .renderer = r
201200}
202201
203- // Debug runs the application in debug mode.
204- func (e * Echo ) Debug (on bool ) {
202+ // SetDebug sets debug mode.
203+ func (e * Echo ) SetDebug (on bool ) {
205204 e .debug = on
206205}
207206
207+ // Debug returns debug mode.
208+ func (e * Echo ) Debug () bool {
209+ return e .debug
210+ }
211+
208212// Use adds handler to the middleware chain.
209213func (e * Echo ) Use (m ... Middleware ) {
210214 for _ , h := range m {
@@ -257,37 +261,20 @@ func (e *Echo) Trace(path string, h Handler) {
257261 e .add (TRACE , path , h )
258262}
259263
260- // URI generates a URI from handler.
261- func (e * Echo ) URI (h Handler , params ... interface {}) string {
262- uri := new (bytes.Buffer )
263- lp := len (params )
264- n := 0
264+ func (e * Echo ) add (method , path string , h Handler ) {
265265 key := runtime .FuncForPC (reflect .ValueOf (h ).Pointer ()).Name ()
266- if path , ok := e .uris [key ]; ok {
267- for i , l := 0 , len (path ); i < l ; i ++ {
268- if path [i ] == ':' && n < lp {
269- for ; i < l && path [i ] != '/' ; i ++ {
270- }
271- uri .WriteString (fmt .Sprintf ("%v" , params [n ]))
272- n ++
273- }
274- if i < l {
275- uri .WriteByte (path [i ])
276- }
277- }
278- }
279- return uri .String ()
266+ e .uris [key ] = path
267+ e .Router .Add (method , e .prefix + path , wrapHandler (h ), e )
280268}
281269
282- // URL is an alias for URI
283- func (e * Echo ) URL ( h Handler , params ... interface {}) string {
284- return e . URI ( h , params ... )
270+ // Index serves index file.
271+ func (e * Echo ) Index ( file string ) {
272+ e . ServeFile ( "/" , file )
285273}
286274
287- func (e * Echo ) add (method , path string , h Handler ) {
288- key := runtime .FuncForPC (reflect .ValueOf (h ).Pointer ()).Name ()
289- e .uris [key ] = path
290- e .Router .Add (method , e .prefix + path , wrapHandler (h ), e )
275+ // Favicon serves the default favicon - GET /favicon.ico.
276+ func (e * Echo ) Favicon (file string ) {
277+ e .ServeFile ("/favicon.ico" , file )
291278}
292279
293280// Static serves static files.
@@ -307,14 +294,31 @@ func (e *Echo) ServeFile(path, file string) {
307294 })
308295}
309296
310- // Index serves index file.
311- func (e * Echo ) Index (file string ) {
312- e .ServeFile ("/" , file )
297+ // URI generates a URI from handler.
298+ func (e * Echo ) URI (h Handler , params ... interface {}) string {
299+ uri := new (bytes.Buffer )
300+ lp := len (params )
301+ n := 0
302+ key := runtime .FuncForPC (reflect .ValueOf (h ).Pointer ()).Name ()
303+ if path , ok := e .uris [key ]; ok {
304+ for i , l := 0 , len (path ); i < l ; i ++ {
305+ if path [i ] == ':' && n < lp {
306+ for ; i < l && path [i ] != '/' ; i ++ {
307+ }
308+ uri .WriteString (fmt .Sprintf ("%v" , params [n ]))
309+ n ++
310+ }
311+ if i < l {
312+ uri .WriteByte (path [i ])
313+ }
314+ }
315+ }
316+ return uri .String ()
313317}
314318
315- // Favicon serves the default favicon - GET /favicon.ico.
316- func (e * Echo ) Favicon ( file string ) {
317- e . ServeFile ( "/favicon.ico" , file )
319+ // URL is an alias for URI
320+ func (e * Echo ) URL ( h Handler , params ... interface {}) string {
321+ return e . URI ( h , params ... )
318322}
319323
320324func (e * Echo ) ServeHTTP (w http.ResponseWriter , r * http.Request ) {
0 commit comments