errorAction.go 764 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package common
  2. import (
  3. "github.com/gogf/gf/frame/g"
  4. "github.com/gogf/gf/net/ghttp"
  5. "github.com/gogf/gf/os/glog"
  6. "github.com/gogf/gf/text/gstr"
  7. "github.com/gogf/gf/util/gconv"
  8. "gmanager/library/base"
  9. )
  10. func Error301(r *ghttp.Request) {
  11. respError(r, 301)
  12. }
  13. func Error404(r *ghttp.Request) {
  14. respError(r, 404)
  15. }
  16. func Error500(r *ghttp.Request) {
  17. respError(r, 500)
  18. }
  19. func respError(r *ghttp.Request, errorCode int) {
  20. glog.Println(r.URL.Path, errorCode, "error page")
  21. if gstr.Contains(r.URL.Path, "html") {
  22. err := r.Response.WriteTpl("error/"+gconv.String(errorCode)+".html", g.Map{
  23. "error": "",
  24. })
  25. if err != nil {
  26. glog.Error(err)
  27. }
  28. } else {
  29. base.Resp(r, errorCode, "error page", r.URL.Path)
  30. }
  31. }