mc_read.go 696 B

1234567891011121314151617181920212223242526272829303132
  1. package main
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "strconv"
  6. )
  7. func ReadLog(w http.ResponseWriter, r *http.Request) {
  8. log := MCServer.ReadAllLog()
  9. jsonData, _ := json.Marshal(log)
  10. sendJSONResponse(w, string(jsonData))
  11. }
  12. func ReadLogFrom(w http.ResponseWriter, r *http.Request) {
  13. start, _ := mv(r, "start", false)
  14. startInt, _ := strconv.Atoi(start)
  15. end := MCServer.LenLog()
  16. //show only first 3000 record if start ~ end is >= 3000
  17. if end-startInt > 3000 {
  18. startInt = end - 3000
  19. }
  20. if startInt > MCServer.LenLog()-1 {
  21. sendJSONResponse(w, "[]")
  22. } else {
  23. log := MCServer.ReadRangeLog(startInt, end)
  24. jsonData, _ := json.Marshal(log)
  25. sendJSONResponse(w, string(jsonData))
  26. }
  27. }