Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

9 роки тому
9 роки тому
9 роки тому
9 роки тому
9 роки тому
9 роки тому
9 роки тому
9 роки тому
9 роки тому
9 роки тому
9 роки тому
9 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package rex
  2. import (
  3. "net/http"
  4. "path/filepath"
  5. "github.com/goanywhere/fs"
  6. "github.com/goanywhere/rex/internal"
  7. . "github.com/goanywhere/rex/middleware"
  8. )
  9. var (
  10. Default = New()
  11. Env *internal.Env
  12. )
  13. // Get is a shortcut for mux.HandleFunc(pattern, handler).Methods("GET"),
  14. // it also fetch the full function name of the handler (with package) to name the route.
  15. func Get(pattern string, handler interface{}) {
  16. Default.Get(pattern, handler)
  17. }
  18. // Head is a shortcut for mux.HandleFunc(pattern, handler).Methods("HEAD")
  19. // it also fetch the full function name of the handler (with package) to name the route.
  20. func Head(pattern string, handler interface{}) {
  21. Default.Head(pattern, handler)
  22. }
  23. // Options is a shortcut for mux.HandleFunc(pattern, handler).Methods("OPTIONS")
  24. // it also fetch the full function name of the handler (with package) to name the route.
  25. // NOTE method OPTIONS is **NOT** cachable, beware of what you are going to do.
  26. func Options(pattern string, handler interface{}) {
  27. Default.Options(pattern, handler)
  28. }
  29. // Post is a shortcut for mux.HandleFunc(pattern, handler).Methods("POST")
  30. // it also fetch the full function name of the handler (with package) to name the route.
  31. func Post(pattern string, handler interface{}) {
  32. Default.Post(pattern, handler)
  33. }
  34. // Put is a shortcut for mux.HandleFunc(pattern, handler).Methods("PUT")
  35. // it also fetch the full function name of the handler (with package) to name the route.
  36. func Put(pattern string, handler interface{}) {
  37. Default.Put(pattern, handler)
  38. }
  39. // Delete is a shortcut for mux.HandleFunc(pattern, handler).Methods("DELETE")
  40. // it also fetch the full function name of the handler (with package) to name the route.
  41. func Delete(pattern string, handler interface{}) {
  42. Default.Delete(pattern, handler)
  43. }
  44. // Group creates a new application group under the given path.
  45. func Group(path string) *Server {
  46. return Default.Group(path)
  47. }
  48. // FileServer registers a handler to serve HTTP (GET|HEAD) requests
  49. // with the contents of file system under the given directory.
  50. func FileServer(prefix, dir string) {
  51. Default.FileServer(prefix, dir)
  52. }
  53. // Use appends middleware module into the serving list, modules will be served in FIFO order.
  54. func Use(module func(http.Handler) http.Handler) {
  55. Default.Use(module)
  56. }
  57. func Run() {
  58. Default.Use(Logger)
  59. Default.Run()
  60. }
  61. func init() {
  62. var basedir = fs.Getcd(2)
  63. Env = internal.New(filepath.Join(basedir, ".env"))
  64. }