Skip to content

Commit

Permalink
fix: add checks to fix errcheck lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorian committed Sep 10, 2024
1 parent ac811fa commit f8dd047
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 12 additions & 2 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,19 @@ func (app *application) metadataHandler(w http.ResponseWriter, r *http.Request)

w.Header().Add("Content-Type", "application/json")

w.Write(output)
_, err = w.Write(output)
if err != nil {
app.logger.Error(err.Error())
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
}

func (app *application) healthCheckHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("okay!"))
_, err := w.Write([]byte("okay!"))
if err != nil {
app.logger.Error(err.Error())
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
}
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ func main() {
logger: logger,
}

http.ListenAndServe(":80", app.routes())
err := http.ListenAndServe(":80", app.routes())
logger.Error(err.Error())
os.Exit(1)
}

0 comments on commit f8dd047

Please sign in to comment.