// Package api provides REST API handlers for Spaxel. package api import ( "encoding/json" "log" "net/http" "strings" ) // writeJSON writes a JSON response with the given status code. func writeJSON(w http.ResponseWriter, status int, v interface{}) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(status) if err := json.NewEncoder(w).Encode(v); err != nil { log.Printf("[ERROR] Failed to encode JSON response: %v", err) } } // writeJSONData writes a JSON response without setting status (assumes status already set). func writeJSONData(w http.ResponseWriter, v interface{}) { w.Header().Set("Content-Type", "application/json") if err := json.NewEncoder(w).Encode(v); err != nil { log.Printf("[ERROR] Failed to encode JSON response: %v", err) } } // writeJSONError writes a JSON error response. func writeJSONError(w http.ResponseWriter, status int, message string) { writeJSON(w, status, map[string]string{"error": message}) } // joinComma joins a slice of strings with ", " separator. func joinComma(parts []string) string { return strings.Join(parts, ", ") }