add some helper structs

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

No files matched your search

+22
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
}