Micro-service for file storage and processing written in Go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
450 B

  1. package auth
  2. import "net/http"
  3. type AuthenticationMiddleware struct {
  4. Secret string
  5. }
  6. func (middleware AuthenticationMiddleware) Middleware(next http.Handler) http.Handler {
  7. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  8. authToken := r.Header.Get("Authorization")
  9. if authToken == "" || authToken != middleware.Secret {
  10. http.Error(w, "Forbidden", http.StatusForbidden)
  11. } else {
  12. next.ServeHTTP(w, r)
  13. }
  14. })
  15. }