add some helper structs
This commit is contained in:
1 parent
2cc1d6f52c
commit
ff51aef518
4 files changed
+61
-1
No files matched your search
@@ -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