16 lines
411 B
Go
16 lines
411 B
Go
package handlers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
func respondWithJSON(w http.ResponseWriter, status int, payload interface{}) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(status)
|
|
json.NewEncoder(w).Encode(payload)
|
|
}
|
|
|
|
func respondWithError(w http.ResponseWriter, status int, message string) {
|
|
respondWithJSON(w, status, map[string]string{"error": message})
|
|
} |