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