application.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package context
  2. import (
  3. "io"
  4. "net/http"
  5. "github.com/kataras/golog"
  6. )
  7. // Application is the context's owner.
  8. // This interface contains the functions that can be used with safety inside a Handler
  9. // by `context.Application()`.
  10. type Application interface {
  11. // ConfigurationReadOnly returns all the available configuration values can be used on a request.
  12. ConfigurationReadOnly() ConfigurationReadOnly
  13. // Logger returns the golog logger instance(pointer) that is being used inside the "app".
  14. Logger() *golog.Logger
  15. // View executes and write the result of a template file to the writer.
  16. //
  17. // Use context.View to render templates to the client instead.
  18. // Returns an error on failure, otherwise nil.
  19. View(writer io.Writer, filename string, layout string, bindingData interface{}) error
  20. // ServeHTTPC is the internal router, it's visible because it can be used for advanced use cases,
  21. // i.e: routing within a foreign context.
  22. //
  23. // It is ready to use after Build state.
  24. ServeHTTPC(ctx Context)
  25. // ServeHTTP is the main router handler which calls the .Serve and acquires a new context from the pool.
  26. //
  27. // It is ready to use after Build state.
  28. ServeHTTP(w http.ResponseWriter, r *http.Request)
  29. // GetRouteReadOnly returns the registered "read-only" route based on its name, otherwise nil.
  30. // One note: "routeName" should be case-sensitive. Used by the context to get the current route.
  31. // It returns an interface instead to reduce wrong usage and to keep the decoupled design between
  32. // the context and the routes.
  33. //
  34. // Look core/router/APIBuilder#GetRoute for more.
  35. GetRouteReadOnly(routeName string) RouteReadOnly
  36. // GetRoutesReadOnly returns the registered "read-only" routes.
  37. //
  38. // Look core/router/APIBuilder#GetRoutes for more.
  39. GetRoutesReadOnly() []RouteReadOnly
  40. // FireErrorCode executes an error http status code handler
  41. // based on the context's status code.
  42. //
  43. // If a handler is not already registered,
  44. // then it creates & registers a new trivial handler on the-fly.
  45. FireErrorCode(ctx Context)
  46. // RouteExists reports whether a particular route exists
  47. // It will search from the current subdomain of context's host, if not inside the root domain.
  48. RouteExists(ctx Context, method, path string) bool
  49. }