Brijesh's Git Server — watchman @ 2d4643bb2dffa04d3cc31d7ef64331bd819bdd5a

observability tool, needs to be rewritten once identity is stable

utils/response.go (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
package utils

import (
	"encoding/json"
	"net/http"
	"watchman/schema"
)

func SendResponse(w http.ResponseWriter, r *http.Request, response schema.Response_Type) {
	w.Header().Set("Content-Type", "application/json")

	err := json.NewEncoder(w).Encode(response)
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)

		json.NewEncoder(w).Encode(schema.Response_Type{
			Status:    "ERROR",
			Message:   "Error encoding response",
			RequestID: r.Context().Value(schema.RequestIDKey{}).(string),
		})
	}
}