handler.go 816 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package statistic
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "imuslab.com/zoraxy/mod/utils"
  6. )
  7. /*
  8. Handler.go
  9. This script handles incoming request for loading the statistic of the day
  10. */
  11. func (c *Collector) HandleTodayStatLoad(w http.ResponseWriter, r *http.Request) {
  12. fast, err := utils.GetPara(r, "fast")
  13. if err != nil {
  14. fast = "false"
  15. }
  16. d := c.DailySummary
  17. if fast == "true" {
  18. //Only return the counter
  19. exported := DailySummaryExport{
  20. TotalRequest: d.TotalRequest,
  21. ErrorRequest: d.ErrorRequest,
  22. ValidRequest: d.ValidRequest,
  23. }
  24. js, _ := json.Marshal(exported)
  25. utils.SendJSONResponse(w, string(js))
  26. } else {
  27. //Return everything
  28. exported := c.GetExportSummary()
  29. js, _ := json.Marshal(exported)
  30. utils.SendJSONResponse(w, string(js))
  31. }
  32. }