1
0
Fork 0
mirror of https://github.com/kyverno/policy-reporter.git synced 2024-12-15 17:50:58 +00:00
policy-reporter/pkg/helper/http.go
Frank Jogeleit cc1db9bd14 Implement new Webhook target for custom tools
Signed-off-by: Frank Jogeleit <frank.jogeleit@web.de>
2022-04-30 11:21:30 +02:00

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()))
}
}