gophertype/pkg/responses/json.go

16 lines
292 B
Go
Raw Normal View History

2020-02-16 04:34:32 +00:00
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)
}