application.go 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package context
  2. import (
  3. stdContext "context"
  4. "io"
  5. "net/http"
  6. "github.com/kataras/golog"
  7. )
  8. // Application is the context's owner.
  9. // This interface contains the functions that can be used with safety inside a Handler
  10. // by `context.Application()`.
  11. type Application interface {
  12. // ConfigurationReadOnly returns all the available configuration values can be used on a request.
  13. ConfigurationReadOnly() ConfigurationReadOnly
  14. // Logger returns the golog logger instance(pointer) that is being used inside the "app".
  15. Logger() *golog.Logger
  16. // I18nReadOnly returns the i18n's read-only features.
  17. I18nReadOnly() I18nReadOnly
  18. // Validate validates a value and returns nil if passed or
  19. // the failure reason if not.
  20. Validate(interface{}) error
  21. // View executes and write the result of a template file to the writer.
  22. //
  23. // Use context.View to render templates to the client instead.
  24. // Returns an error on failure, otherwise nil.
  25. View(writer io.Writer, filename string, layout string, bindingData interface{}) error
  26. // ServeHTTPC is the internal router, it's visible because it can be used for advanced use cases,
  27. // i.e: routing within a foreign context.
  28. //
  29. // It is ready to use after Build state.
  30. ServeHTTPC(ctx *Context)
  31. // ServeHTTP is the main router handler which calls the .Serve and acquires a new context from the pool.
  32. //
  33. // It is ready to use after Build state.
  34. ServeHTTP(w http.ResponseWriter, r *http.Request)
  35. // Shutdown gracefully terminates all the application's server hosts and any tunnels.
  36. // Returns an error on the first failure, otherwise nil.
  37. Shutdown(ctx stdContext.Context) error
  38. // GetRouteReadOnly returns the registered "read-only" route based on its name, otherwise nil.
  39. // One note: "routeName" should be case-sensitive. Used by the context to get the current route.
  40. // It returns an interface instead to reduce wrong usage and to keep the decoupled design between
  41. // the context and the routes.
  42. //
  43. // Look core/router/APIBuilder#GetRoute for more.
  44. GetRouteReadOnly(routeName string) RouteReadOnly
  45. // GetRoutesReadOnly returns the registered "read-only" routes.
  46. //
  47. // Look core/router/APIBuilder#GetRoutes for more.
  48. GetRoutesReadOnly() []RouteReadOnly
  49. // FireErrorCode handles the response's error response.
  50. // If `Configuration.ResetOnFireErrorCode()` is true
  51. // and the response writer was a recorder or a gzip writer one
  52. // then it will try to reset the headers and the body before calling the
  53. // registered (or default) error handler for that error code set by
  54. // `ctx.StatusCode` method.
  55. FireErrorCode(ctx *Context)
  56. // RouteExists reports whether a particular route exists
  57. // It will search from the current subdomain of context's host, if not inside the root domain.
  58. RouteExists(ctx *Context, method, path string) bool
  59. // FindClosestPaths returns a list of "n" paths close to "path" under the given "subdomain".
  60. //
  61. // Order may change.
  62. FindClosestPaths(subdomain, searchPath string, n int) []string
  63. }