@@ -46,6 +46,10 @@ and message `HTTPError.Message`.
46
46
47
47
Enables debug mode.
48
48
49
+ ### Disable colored log
50
+
51
+ ` Echo.DisableColoredLog() `
52
+
49
53
## Routing
50
54
51
55
Echo's router is [ fast, optimized] ( https://github.com/labstack/echo#benchmark ) and
@@ -299,30 +303,90 @@ $ curl -d "name=joe" http://localhost:1323/users
299
303
300
304
## Response
301
305
306
+ ### Template
307
+
308
+ ``` go
309
+ Context.Render (code int , name string , data interface {}) error
310
+ ```
311
+ Renders a template with data and sends a text/html response with status code. Templates
312
+ can be registered using ` Echo.SetRenderer() ` , allowing us to use any templating engine.
313
+ Below is an example using Go ` html/template `
314
+
315
+ Implement ` echo.Render `
316
+
317
+ ``` go
318
+ Template struct {
319
+ templates *template.Template
320
+ }
321
+
322
+ func (t *Template ) Render (w io .Writer , name string , data interface {}) error {
323
+ return t.templates .ExecuteTemplate (w, name, data)
324
+ }
325
+ ```
326
+
327
+ Pre-compile templates
328
+
329
+ ``` go
330
+ t := &Template{
331
+ templates: template.Must (template.ParseGlob (" public/views/*.html" )),
332
+ }
333
+ ```
334
+
335
+ Register templates
336
+
337
+ ``` go
338
+ e := echo.New ()
339
+ e.SetRenderer (t)
340
+ e.Get (" /hello" , Hello )
341
+ ```
342
+
343
+ Template ` public/views/hello.html `
344
+
345
+ ``` html
346
+ {{define "hello"}}Hello, {{.}}!{{end}}
347
+
348
+ ```
349
+
350
+ Handler
351
+
352
+ ``` go
353
+ func Hello (c *echo .Context ) error {
354
+ return c.Render (http.StatusOK , " hello" , " World" )
355
+ }
356
+ ```
357
+
302
358
### JSON
303
359
304
360
``` go
305
- context .JSON (code int , v interface {}) error
361
+ Context .JSON (code int , v interface {}) error
306
362
```
307
363
308
364
Sends a JSON HTTP response with status code.
309
365
310
- ### String
366
+ ### XML
311
367
312
368
``` go
313
- context. String (code int , s string ) error
369
+ Context. XML (code int , v interface {} ) error
314
370
```
315
371
316
- Sends a text/plain HTTP response with status code.
372
+ Sends an XML HTTP response with status code.
317
373
318
374
### HTML
319
375
320
376
``` go
321
- func ( c * Context ) HTML (code int , html string ) error
377
+ Context. HTML (code int , html string ) error
322
378
```
323
379
324
380
Sends an HTML HTTP response with status code.
325
381
382
+ ### String
383
+
384
+ ``` go
385
+ Context.String (code int , s string ) error
386
+ ```
387
+
388
+ Sends a text/plain HTTP response with status code.
389
+
326
390
### Static files
327
391
328
392
` Echo.Static(path, root string) ` serves static files. For example, code below serves
0 commit comments