Various cleanup in endpoints.go

This commit is contained in:
Pancakes 2025-04-25 19:50:11 -04:00
parent ef9b659127
commit 7da9a39e1b
No known key found for this signature in database
GPG Key ID: 5792877BFA27DC8F

View File

@ -144,7 +144,7 @@ func handleGameTitleStats(w http.ResponseWriter, r *http.Request) {
} }
func handleGameClassicSessionCount(w http.ResponseWriter, r *http.Request) { func handleGameClassicSessionCount(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(strconv.Itoa(classicSessionCount))) fmt.Fprint(w, classicSessionCount)
} }
func handleSession(w http.ResponseWriter, r *http.Request) { func handleSession(w http.ResponseWriter, r *http.Request) {
@ -179,12 +179,12 @@ func handleSession(w http.ResponseWriter, r *http.Request) {
switch r.PathValue("action") { switch r.PathValue("action") {
case "get": case "get":
save, err := savedata.GetSession(uuid, slot) save, err := savedata.GetSession(uuid, slot)
if errors.Is(err, savedata.ErrSaveNotExist) {
http.Error(w, err.Error(), http.StatusNotFound)
return
}
if err != nil { if err != nil {
if errors.Is(err, savedata.ErrSaveNotExist) {
http.Error(w, err.Error(), http.StatusNotFound)
return
}
httpError(w, r, err, http.StatusInternalServerError) httpError(w, r, err, http.StatusInternalServerError)
return return
} }
@ -398,10 +398,10 @@ func handleSystem(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
if errors.Is(err, savedata.ErrSaveNotExist) { if errors.Is(err, savedata.ErrSaveNotExist) {
http.Error(w, err.Error(), http.StatusNotFound) http.Error(w, err.Error(), http.StatusNotFound)
} else { return
httpError(w, r, fmt.Errorf("failed to get system save data: %s", err), http.StatusInternalServerError)
} }
httpError(w, r, fmt.Errorf("failed to get system save data: %s", err), http.StatusInternalServerError)
return return
} }
@ -489,10 +489,7 @@ func handleDailySeed(w http.ResponseWriter, r *http.Request) {
return return
} }
_, err = w.Write([]byte(seed)) fmt.Fprint(w, seed)
if err != nil {
httpError(w, r, fmt.Errorf("failed to write seed: %s", err), http.StatusInternalServerError)
}
} }
func handleDailyRankings(w http.ResponseWriter, r *http.Request) { func handleDailyRankings(w http.ResponseWriter, r *http.Request) {
@ -541,7 +538,7 @@ func handleDailyRankingPageCount(w http.ResponseWriter, r *http.Request) {
httpError(w, r, err, http.StatusInternalServerError) httpError(w, r, err, http.StatusInternalServerError)
} }
w.Write([]byte(strconv.Itoa(count))) fmt.Fprint(w, count)
} }
// redirect link after authorizing application link // redirect link after authorizing application link