mirror of
https://github.com/kyverno/policy-reporter.git
synced 2024-12-15 17:50:58 +00:00
cc1db9bd14
Signed-off-by: Frank Jogeleit <frank.jogeleit@web.de>
25 lines
574 B
Go
25 lines
574 B
Go
package helper
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"html"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
func SendJSONResponse(w http.ResponseWriter, list interface{}, err error) {
|
|
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
|
if err != nil {
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
fmt.Fprintf(w, `{ "message": "%s" }`, html.EscapeString(err.Error()))
|
|
|
|
return
|
|
}
|
|
|
|
if err := json.NewEncoder(w).Encode(list); err != nil {
|
|
log.Println(err)
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
fmt.Fprintf(w, `{ "message": "%s" }`, html.EscapeString(err.Error()))
|
|
}
|
|
}
|