Is there a way to set json header to all routes?
func Ping(rw http.ResponseWriter, r *http.Request) {
rw.Header().Set("Content-Type", "application/json")
json.NewEncoder(rw).Encode(map[string]string{"Status": "OK"})
}
func Lol(rw http.ResponseWriter, r *http.Request) {
rw.Header().Set("Content-Type", "application/json")
json.NewEncoder(rw).Encode(map[string]string{"Status": "OK"})
}
not to duplicate this
json.NewEncoder(rw).Encode(map[string]string{"Status": "OK"})
You can use
middlewareto addContent-Type: application/jsonheader to each handlerThen register the
middlewaretogorilla/muxas below