Brijesh's Git Server — watchman @ 2960f2fd873b37cded9c2d861c37f90e0c3f08e6

observability tool, needs to be rewritten once identity is stable

utils/errors.go (view raw)

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

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

func HandleMethodNotAllowed(w http.ResponseWriter, r *http.Request, method string) {
	if r.Method != method {
		response := schema.Response_Type{
			Status:    "ERROR",
			Message:   "Method " + method + " not allowed",
			RequestID: r.Context().Value(schema.RequestIDKey{}).(string),
		}

		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(http.StatusMethodNotAllowed)
		json.NewEncoder(w).Encode(response)
	}
}