Initial add backend stuff
This commit is contained in:
20
httputil/respond.go
Normal file
20
httputil/respond.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package httputil
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func RespondJSON(w http.ResponseWriter, statusCode int, data any) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(statusCode)
|
||||
json.NewEncoder(w).Encode(data)
|
||||
}
|
||||
|
||||
func RespondError(w http.ResponseWriter, statusCode int, message string) {
|
||||
RespondJSON(w, statusCode, map[string]string{"error": message})
|
||||
}
|
||||
|
||||
func RespondSuccess(w http.ResponseWriter) {
|
||||
RespondJSON(w, http.StatusOK, map[string]bool{"success": true})
|
||||
}
|
||||
Reference in New Issue
Block a user