Brijesh's Git Server — watchman @ cd48349fb70225313368346a4b01af65c5a3b7b0

observability tool, needs to be rewritten once identity is stable

utils/common_handlers.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
 23
 24
 25
package utils

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

func Health_Check_Handler(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte("OK"))
}

func Example_Handler(w http.ResponseWriter, r *http.Request) {
	response := schema.Response_Type{
		Status:    "OK",
		Message:   "Everything is fine",
		RequestID: r.Context().Value(schema.RequestIDKey{}).(string),
	}

	w.Header().Set("Content-Type", "application/json")
	err := json.NewEncoder(w).Encode(response)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}