1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00
wakapi/utils/http.go

16 lines
398 B
Go
Raw Permalink Normal View History

package utils
import (
"encoding/json"
2021-04-16 16:59:39 +03:00
"github.com/muety/wakapi/config"
"net/http"
)
func RespondJSON(w http.ResponseWriter, r *http.Request, status int, object interface{}) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
if err := json.NewEncoder(w).Encode(object); err != nil {
config.Log().Request(r).Error("error while writing json response: %v", err)
}
}