package routes import ( "net/http" "log" "os" ) type Middleware func(http.Handler) http.Handler func MultipleMiddleware(h http.Handler, m ...Middleware) http.Handler { if len(m) < 1 { return h } wrapped := h for i := len(m) - 1; i >= 0; i-- { wrapped = m[i](wrapped) } return wrapped } // func authMiddleware(h http.Handler) http.Handler { // return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // _, ok := ValidateUserToken(r) // // if ok { // next.ServeHTTP(w, r) // } else { // w.WriteHeader(http.StatusUnauthorized) // } // }) // } func logMiddleware(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { log.SetOutput(os.Stdout) log.Println(r.Method, r.URL) h.ServeHTTP(w, r) }) }