deprecated.go 1.2 KB

123456789101112131415161718192021222324252627282930313233
  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.Req, 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. }