package api import ( "encoding/json" "net/http" ) // writeJSON writes a JSON response with the given status code. func writeJSON(w http.ResponseWriter, status int, v any) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(status) json.NewEncoder(w).Encode(v) } // errorBody creates a standard error response body. func errorBody(code, message string) map[string]string { return map[string]string{ "error": code, "message": message, } } // truncateStr truncates a string to the given length, appending "..." if truncated. func truncateStr(s string, maxLen int) string { if len(s) <= maxLen { return s } if maxLen <= 3 { return s[:maxLen] } return s[:maxLen-3] + "..." }