SetContentTypeByExt

通过文件(文件后缀)设置Content-Type。

Example

  1. package main
  2. import (
  3. "github.com/vicanso/elton"
  4. "github.com/vicanso/elton/middleware"
  5. )
  6. func main() {
  7. e := elton.New()
  8. e.Use(middleware.NewDefaultResponder())
  9. e.GET("/", func(c *elton.Context) (err error) {
  10. c.SetContentTypeByExt(".html")
  11. c.Body = `<html>
  12. <body>
  13. <p>Hello, World!</p>
  14. </body>
  15. </html>`
  16. return
  17. })
  18. err := e.ListenAndServe(":3000")
  19. if err != nil {
  20. panic(err)
  21. }
  22. }