add options for components
This commit is contained in:
10
auth/auth.go
10
auth/auth.go
@ -2,9 +2,13 @@ package auth
|
||||
|
||||
import "context"
|
||||
|
||||
type Options struct{}
|
||||
|
||||
type Option func(opts *Options)
|
||||
|
||||
// Authenticator is an interface for user authentication.
|
||||
type Authenticator interface {
|
||||
Authenticate(ctx context.Context, user, password string) (id string, ok bool)
|
||||
Authenticate(ctx context.Context, user, password string, opts ...Option) (id string, ok bool)
|
||||
}
|
||||
|
||||
type authenticatorGroup struct {
|
||||
@ -17,7 +21,7 @@ func AuthenticatorGroup(authers ...Authenticator) Authenticator {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *authenticatorGroup) Authenticate(ctx context.Context, user, password string) (string, bool) {
|
||||
func (p *authenticatorGroup) Authenticate(ctx context.Context, user, password string, opts ...Option) (string, bool) {
|
||||
if len(p.authers) == 0 {
|
||||
return "", false
|
||||
}
|
||||
@ -26,7 +30,7 @@ func (p *authenticatorGroup) Authenticate(ctx context.Context, user, password st
|
||||
continue
|
||||
}
|
||||
|
||||
if id, ok := auther.Authenticate(ctx, user, password); ok {
|
||||
if id, ok := auther.Authenticate(ctx, user, password, opts...); ok {
|
||||
return id, ok
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user