Start refactoring

This commit is contained in:
Aurélie Delhaie
2023-05-29 17:44:50 +02:00
parent 55ac50f3be
commit c06843cd28
31 changed files with 1125 additions and 1267 deletions

36
server/middleware.go Normal file
View File

@@ -0,0 +1,36 @@
package server
import "net/http"
// authMiddleware check the authentication token before accessing to the resource
func (s *HTTPServer) authMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// TODO
})
}
// adminMiddleware check the role of the user before accessing to the resource
func (s *HTTPServer) adminMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// TODO
})
}
// uploadMiddleware check the upload key before allowing to upload a file
func (s *HTTPServer) uploadMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// TODO
})
}
func recoverMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer func() {
err := recover()
if err != nil {
internalServerError(w, r)
}
}()
next.ServeHTTP(w, r)
})
}