diff options
author | Alex <alex@scerba.org> | 2024-05-04 17:28:37 -0400 |
---|---|---|
committer | Alex Scerba <alex@scerba.org> | 2024-08-15 22:54:25 -0500 |
commit | 811c9bb2f7358ff094fe13deb6d961088baa2d8f (patch) | |
tree | 694010fbc71c9ff67cee28f6da1447290e627afe /cmd/http/errors.go | |
parent | d9fc74778ef86b02f0a743821263db8873417294 (diff) |
Add Go webserver.
Diffstat (limited to 'cmd/http/errors.go')
-rw-r--r-- | cmd/http/errors.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/cmd/http/errors.go b/cmd/http/errors.go new file mode 100644 index 0000000..9406a9a --- /dev/null +++ b/cmd/http/errors.go @@ -0,0 +1,23 @@ +package main + +import ( + "fmt" + "net/http" + "runtime/debug" +) + +func (app *application) serverError(w http.ResponseWriter, err error) { + trace := fmt.Sprintf("%s\n%s", err.Error(), debug.Stack()) + app.errorLog.Output(2, trace) + + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) +} + +func (app *application) clientError(w http.ResponseWriter, status int) { + app.errorLog.Printf("Clent error: %d\n", status) + http.Error(w, http.StatusText(status), status) +} + +func (app *application) notFound(w http.ResponseWriter) { + app.clientError(w, http.StatusNotFound) +} |