mirror of
https://github.com/amir20/dozzle.git
synced 2025-12-25 23:03:47 +01:00
26 lines
621 B
Go
26 lines
621 B
Go
package web
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/amir20/dozzle/internal/content"
|
|
"github.com/go-chi/chi/v5"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func (h *handler) staticContent(w http.ResponseWriter, r *http.Request) {
|
|
id := chi.URLParam(r, "id")
|
|
content, err := content.Read(id)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
log.Warnf("error reading content: %v", err)
|
|
return
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
if err := json.NewEncoder(w).Encode(content); err != nil {
|
|
log.Errorf("json encoding error while streaming %v", err.Error())
|
|
}
|
|
}
|