lot of new functionalities
This commit is contained in:
31
servers/web/api/export.go
Normal file
31
servers/web/api/export.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (h *Handler) CacheExport(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
cacheID := vars["cacheid"]
|
||||
|
||||
result, err := h.applicationHandler.ExportCacheAsCSV(cacheID)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Error exporting cache")
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/csv")
|
||||
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=export-%s.csv", cacheID))
|
||||
|
||||
csvWriter := csv.NewWriter(w)
|
||||
defer csvWriter.Flush()
|
||||
|
||||
csvWriter.Write(result.Headers)
|
||||
csvWriter.WriteAll(result.Values)
|
||||
}
|
||||
Reference in New Issue
Block a user