solidarity transport updates
This commit is contained in:
19
utils/protectapi/api_key.go
Normal file
19
utils/protectapi/api_key.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package protectapi
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func ApiKey(apiKey string) func(http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if apiKey == "" || r.Header.Get("X_API_KEY") != apiKey {
|
||||
log.Info().Msg("call to api not allowed")
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
}
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user