add some helper structs

This commit is contained in:
ginuerzh
2022-08-23 21:46:27 +08:00
parent 2cc1d6f52c
commit ff51aef518
4 changed files with 61 additions and 1 deletions

View File

@ -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
}