deprecated.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package gin
  2. import (
  3. "github.com/gin-gonic/gin/binding"
  4. "net/http"
  5. )
  6. // DEPRECATED, use Bind() instead.
  7. // Like ParseBody() but this method also writes a 400 error if the json is not valid.
  8. func (c *Context) EnsureBody(item interface{}) bool {
  9. return c.Bind(item)
  10. }
  11. // DEPRECATED use bindings directly
  12. // Parses the body content as a JSON input. It decodes the json payload into the struct specified as a pointer.
  13. func (c *Context) ParseBody(item interface{}) error {
  14. return binding.JSON.Bind(c.Request, item)
  15. }
  16. // DEPRECATED use gin.Static() instead
  17. // ServeFiles serves files from the given file system root.
  18. // The path must end with "/*filepath", files are then served from the local
  19. // path /defined/root/dir/*filepath.
  20. // For example if root is "/etc" and *filepath is "passwd", the local file
  21. // "/etc/passwd" would be served.
  22. // Internally a http.FileServer is used, therefore http.NotFound is used instead
  23. // of the Router's NotFound handler.
  24. // To use the operating system's file system implementation,
  25. // use http.Dir:
  26. // router.ServeFiles("/src/*filepath", http.Dir("/var/www"))
  27. func (engine *Engine) ServeFiles(path string, root http.FileSystem) {
  28. engine.router.ServeFiles(path, root)
  29. }
  30. // DEPRECATED use gin.LoadHTMLGlob() or gin.LoadHTMLFiles() instead
  31. func (engine *Engine) LoadHTMLTemplates(pattern string) {
  32. engine.LoadHTMLGlob(pattern)
  33. }
  34. // DEPRECATED. Use NotFound() instead
  35. func (engine *Engine) NotFound404(handlers ...HandlerFunc) {
  36. engine.NoRoute(handlers...)
  37. }