Files
dns_service/utils/response_json.go
T
wt efcb19aa2f
Build / Build (push) Successful in 32s
more optimizations
2025-07-07 22:40:06 +07:00

19 lines
402 B
Go

package utils
import (
"encoding/json"
"net/http"
)
// Helper to write JSON responses
func RespondWithJSON(w http.ResponseWriter, data any, statusCode int) {
jsonData, err := json.Marshal(data)
if err != nil {
http.Error(w, "failed to marshal JSON", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(statusCode)
w.Write(jsonData)
}