core/auth/auth.go
2022-09-02 10:54:42 +08:00

29 lines
579 B
Go

package auth
// Authenticator is an interface for user authentication.
type Authenticator interface {
Authenticate(user, password string) bool
}
type authenticatorGroup struct {
authers []Authenticator
}
func AuthenticatorGroup(authers ...Authenticator) Authenticator {
return &authenticatorGroup{
authers: authers,
}
}
func (p *authenticatorGroup) 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
}