handlers.go 796 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package authlogger
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. )
  6. //Handle of listing of the logger index (months)
  7. func (l *Logger) HandleIndexListing(w http.ResponseWriter, r *http.Request) {
  8. indexes := l.ListSummary()
  9. js, err := json.Marshal(indexes)
  10. if err != nil {
  11. sendErrorResponse(w, err.Error())
  12. return
  13. }
  14. sendJSONResponse(w, string(js))
  15. }
  16. //Handle of the listing of a given index (month)
  17. func (l *Logger) HandleTableListing(w http.ResponseWriter, r *http.Request) {
  18. //Get the record name request for listing
  19. month, err := mv(r, "record", true)
  20. if err != nil {
  21. sendErrorResponse(w, err.Error())
  22. return
  23. }
  24. records, err := l.ListRecords(month)
  25. if err != nil {
  26. sendErrorResponse(w, err.Error())
  27. return
  28. }
  29. js, _ := json.Marshal(records)
  30. sendJSONResponse(w, string(js))
  31. }