44 lines
961 B
Go
44 lines
961 B
Go
package httpx
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"net/url"
|
|
"shelves/backend/errorsx"
|
|
"shelves/backend/urls"
|
|
)
|
|
|
|
func SeeOther(w http.ResponseWriter, location string) {
|
|
w.Header().Add("Location", location)
|
|
w.WriteHeader(http.StatusSeeOther)
|
|
}
|
|
|
|
func TemporaryRedirect(w http.ResponseWriter, location string) {
|
|
w.Header().Add("Location", location)
|
|
w.WriteHeader(http.StatusTemporaryRedirect)
|
|
}
|
|
|
|
func Unauthorized(w http.ResponseWriter) {
|
|
w.WriteHeader(http.StatusUnauthorized)
|
|
}
|
|
|
|
func BadRequest(w http.ResponseWriter) {
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
}
|
|
|
|
func OK(w http.ResponseWriter) {
|
|
w.WriteHeader(http.StatusOK)
|
|
}
|
|
|
|
func InternalServerError(w http.ResponseWriter, err error) {
|
|
log.Printf("Internal server error: %v", err)
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
w.Write([]byte(errorsx.String(err)))
|
|
}
|
|
|
|
func LoginRedirect(w http.ResponseWriter, redirectTo url.URL) {
|
|
location := urls.Login(redirectTo.Path)
|
|
TemporaryRedirect(w, location)
|
|
}
|