hooker/auth.go

29 lines
540 B
Go

package main
import (
"log"
"net/http"
)
// Java like
const TAG = "[ Auth ]"
type AuthHandler struct {
Handler http.Handler
}
func (l *AuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
AuthHeader := r.Header.Get("Authorization")
RealIP := r.Header.Get("X-Real-IP")
if AuthHeader != task.Auth {
log.Printf("%s Dropping request from %s", TAG, RealIP)
return // drop
}
l.Handler.ServeHTTP(w, r)
}
func NewAuth(handler http.Handler) AuthHandler {
return AuthHandler{handler}
}