16 lines
292 B
Go
16 lines
292 B
Go
package responses
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
// JSON sends a JSON payload as response.
|
|
func JSON(w http.ResponseWriter, statusCode int, v interface{}) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(statusCode)
|
|
|
|
enc := json.NewEncoder(w)
|
|
enc.Encode(v)
|
|
}
|