Add: Simple user login/register function

This commit is contained in:
2021-12-11 18:47:25 +08:00
parent c580ca245f
commit f3a95973e9
11 changed files with 379 additions and 13 deletions

View File

@@ -6,6 +6,10 @@ import (
"net/http"
)
type Error struct {
Error string `json:"error,omitempty"`
}
func (api *API) HandleError(w http.ResponseWriter, r *http.Request, err error) {
api.HandleErrorString(w, r, err.Error())
}
@@ -20,8 +24,8 @@ func (api *API) HandleErrorString(w http.ResponseWriter, r *http.Request, errorS
func (api *API) HandleErrorStringCode(w http.ResponseWriter, r *http.Request, errorString string, code int) {
log.Println("[api] [Error]", code, errorString)
errStatus := &Status{
Status: errorString,
errStatus := &Error{
Error: errorString,
}
w.WriteHeader(code)
json.NewEncoder(w).Encode(errStatus)