error.go 855 B

12345678910111213141516171819202122232425262728293031323334
  1. package agi
  2. import (
  3. "net/http"
  4. "io/ioutil"
  5. "strconv"
  6. "time"
  7. "github.com/valyala/fasttemplate"
  8. )
  9. /*
  10. Error Template Rendering for AGI script error
  11. This script is used to handle a PHP-like error message for the user
  12. For any runtime error, please see the console for more information.
  13. */
  14. func (g *Gateway)RenderErrorTemplate(w http.ResponseWriter, errmsg string, scriptpath string){
  15. template, _ := ioutil.ReadFile("system/agi/error.html")
  16. t := fasttemplate.New(string(template), "{{", "}}")
  17. s := t.ExecuteString(map[string]interface{}{
  18. "error_msg": errmsg,
  19. "script_filepath": scriptpath,
  20. "timestamp": strconv.Itoa(int(time.Now().Unix())),
  21. "major_version": g.Option.BuildVersion,
  22. "minor_version": g.Option.InternalVersion,
  23. "agi_version": AgiVersion,
  24. })
  25. w.WriteHeader(http.StatusInternalServerError)
  26. w.Write([]byte(s))
  27. }