2019-05-19 20:49:27 +03:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2020-10-16 16:16:43 +03:00
|
|
|
"log"
|
2019-05-19 20:49:27 +03:00
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
func RespondJSON(w http.ResponseWriter, status int, object interface{}) {
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
w.WriteHeader(status)
|
|
|
|
if err := json.NewEncoder(w).Encode(object); err != nil {
|
2020-10-16 16:16:43 +03:00
|
|
|
log.Printf("error while writing json response: %v", err)
|
2019-05-19 20:49:27 +03:00
|
|
|
}
|
|
|
|
}
|
2020-05-24 14:41:19 +03:00
|
|
|
|
2020-05-30 13:11:21 +03:00
|
|
|
func ClearCookie(w http.ResponseWriter, name string, secure bool) {
|
2020-05-24 14:41:19 +03:00
|
|
|
http.SetCookie(w, &http.Cookie{
|
|
|
|
Name: name,
|
|
|
|
Value: "",
|
|
|
|
Path: "/",
|
2020-05-30 13:11:21 +03:00
|
|
|
Secure: secure,
|
2020-05-24 14:41:19 +03:00
|
|
|
HttpOnly: true,
|
|
|
|
})
|
|
|
|
}
|