// Respond sends JSON type response to the client.
Respond sends JSON type response to the client.
// Respond sends JSON type response to the client .
func Respond(log zerolog.Logger, w http.ResponseWriter, r *http.Request, data interface{}, code int) {
	if data == nil {
		w.WriteHeader(code)
		return
	}
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(code)
	if err := json.NewEncoder(w).Encode(data); err != nil {
		logutil.Critical(log, err).Msg("cannot send a response")
		err = NewError(nil, http.StatusInternalServerError, "")
		json.NewEncoder(w).Encode(err) 
		w.WriteHeader(http.StatusInternalServerError)
	}
}
func Respond ( log zerolog . Logger , w http . ResponseWriter , r * http . Request , data interface { } , code int ) { if data == nil { w . WriteHeader ( code ) return } w . Header ( ) . Set ( " " , " " ) w . WriteHeader ( code ) if err := json . NewEncoder ( w ) . Encode ( data ) ; err != nil { logutil . Critical ( log , err ) . Msg ( " " ) err = NewError ( nil , http . StatusInternalServerError , " " ) json . NewEncoder ( w ) . Encode ( err ) w . WriteHeader ( http . StatusInternalServerError ) } }
Respond sends JSON type response to the client.
Respond sends JSON type response to the client .
//nolint:errcheck,gosec // error provides no meaningful info