add some helper structs
This commit is contained in:
22
auth/auth.go
22
auth/auth.go
@ -4,3 +4,25 @@ package auth
|
||||
type Authenticator interface {
|
||||
Authenticate(user, password string) bool
|
||||
}
|
||||
|
||||
type authenticatorList struct {
|
||||
authers []Authenticator
|
||||
}
|
||||
|
||||
func AuthenticatorList(authers ...Authenticator) Authenticator {
|
||||
return &authenticatorList{
|
||||
authers: authers,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *authenticatorList) Authenticate(user, password string) bool {
|
||||
if len(p.authers) == 0 {
|
||||
return true
|
||||
}
|
||||
for _, auther := range p.authers {
|
||||
if auther != nil && auther.Authenticate(user, password) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Reference in New Issue
Block a user