deprecated.go 1.6 KB

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