From 15e4d10fd4b35a2e70cc4fa6ad4117cd5c402cbc Mon Sep 17 00:00:00 2001 From: Quentin Date: Mon, 23 Aug 2021 20:40:03 +0200 Subject: Refactor the codebase --- error.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 error.go (limited to 'error.go') diff --git a/error.go b/error.go new file mode 100644 index 0000000..114bbf1 --- /dev/null +++ b/error.go @@ -0,0 +1,24 @@ +package main + +import ( + "net/http" +) + +type NotAuthorized struct{} + +func (n NotAuthorized) WithError(err error) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("WWW-Authenticate", `Basic realm="Pour accéder à Bagage, veuillez entrer vos identifiants Deuxfleurs"`) + w.WriteHeader(401) + w.Write([]byte("401 Unauthorized\n")) + }) +} + +type InternalError struct{} + +func (i InternalError) WithError(err error) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(500) + w.Write([]byte("500 Internal Server Error\n")) + }) +} -- cgit v1.2.3