violet/utils/response.go

17 lines
409 B
Go
Raw Normal View History

2023-04-21 03:21:46 +01:00
package utils
import (
"fmt"
"net/http"
)
// RespondHttpStatus outputs the status code and text using http.Error()
2023-04-21 03:21:46 +01:00
func RespondHttpStatus(rw http.ResponseWriter, status int) {
http.Error(rw, fmt.Sprintf("%d %s", status, http.StatusText(status)), status)
2023-04-21 03:21:46 +01:00
}
2023-06-03 19:33:06 +01:00
func RespondVioletError(rw http.ResponseWriter, status int, msg string) {
rw.Header().Set("X-Violet-Error", msg)
RespondHttpStatus(rw, status)
}