package handler import ( "encoding/json" "log" "net/http" ) func JsonResponse(w http.ResponseWriter, statusCode int, payload interface{}) { w.Header().Set("Content-Type", "application/json") data, err := json.Marshal(payload) if err != nil { log.Printf("Error marshalling JSON: %v", err) w.WriteHeader(http.StatusInternalServerError) return } w.WriteHeader(statusCode) w.Write(data) }