add options for components
This commit is contained in:
parent
6431cd8bb9
commit
9e767d6745
@ -2,8 +2,11 @@ package admission
|
|||||||
|
|
||||||
import "context"
|
import "context"
|
||||||
|
|
||||||
|
type Options struct{}
|
||||||
|
type Option func(opts *Options)
|
||||||
|
|
||||||
type Admission interface {
|
type Admission interface {
|
||||||
Admit(ctx context.Context, addr string) bool
|
Admit(ctx context.Context, addr string, opts ...Option) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type admissionGroup struct {
|
type admissionGroup struct {
|
||||||
@ -16,9 +19,9 @@ func AdmissionGroup(admissions ...Admission) Admission {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *admissionGroup) Admit(ctx context.Context, addr string) bool {
|
func (p *admissionGroup) Admit(ctx context.Context, addr string, opts ...Option) bool {
|
||||||
for _, admission := range p.admissions {
|
for _, admission := range p.admissions {
|
||||||
if admission != nil && !admission.Admit(ctx, addr) {
|
if admission != nil && !admission.Admit(ctx, addr, opts...) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
auth/auth.go
10
auth/auth.go
@ -2,9 +2,13 @@ package auth
|
|||||||
|
|
||||||
import "context"
|
import "context"
|
||||||
|
|
||||||
|
type Options struct{}
|
||||||
|
|
||||||
|
type Option func(opts *Options)
|
||||||
|
|
||||||
// Authenticator is an interface for user authentication.
|
// Authenticator is an interface for user authentication.
|
||||||
type Authenticator interface {
|
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 {
|
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 {
|
if len(p.authers) == 0 {
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
@ -26,7 +30,7 @@ func (p *authenticatorGroup) Authenticate(ctx context.Context, user, password st
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if id, ok := auther.Authenticate(ctx, user, password); ok {
|
if id, ok := auther.Authenticate(ctx, user, password, opts...); ok {
|
||||||
return id, ok
|
return id, ok
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,11 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Options struct{}
|
||||||
|
|
||||||
|
type Option func(opts *Options)
|
||||||
|
|
||||||
// HostMapper is a mapping from hostname to IP.
|
// HostMapper is a mapping from hostname to IP.
|
||||||
type HostMapper interface {
|
type HostMapper interface {
|
||||||
Lookup(ctx context.Context, network, host string) ([]net.IP, bool)
|
Lookup(ctx context.Context, network, host string, opts ...Option) ([]net.IP, bool)
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,15 @@ package ingress
|
|||||||
|
|
||||||
import "context"
|
import "context"
|
||||||
|
|
||||||
|
type GetOptions struct{}
|
||||||
|
|
||||||
|
type GetOption func(opts *GetOptions)
|
||||||
|
|
||||||
|
type SetOptions struct{}
|
||||||
|
|
||||||
|
type SetOption func(opts *SetOptions)
|
||||||
|
|
||||||
type Ingress interface {
|
type Ingress interface {
|
||||||
Get(ctx context.Context, host string) string
|
Get(ctx context.Context, host string, opts ...GetOption) string
|
||||||
Set(ctx context.Context, host, endpoint string)
|
Set(ctx context.Context, host, endpoint string, opts ...SetOption)
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,11 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type RecordOptions struct{}
|
||||||
|
type RecordOption func(opts *RecordOptions)
|
||||||
|
|
||||||
type Recorder interface {
|
type Recorder interface {
|
||||||
Record(ctx context.Context, b []byte) error
|
Record(ctx context.Context, b []byte, opts ...RecordOption) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type RecorderObject struct {
|
type RecorderObject struct {
|
||||||
|
@ -10,8 +10,12 @@ var (
|
|||||||
ErrInvalid = errors.New("invalid resolver")
|
ErrInvalid = errors.New("invalid resolver")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Options struct{}
|
||||||
|
|
||||||
|
type Option func(opts *Options)
|
||||||
|
|
||||||
type Resolver interface {
|
type Resolver interface {
|
||||||
// Resolve returns a slice of the host's IPv4 and IPv6 addresses.
|
// Resolve returns a slice of the host's IPv4 and IPv6 addresses.
|
||||||
// The network should be 'ip', 'ip4' or 'ip6', default network is 'ip'.
|
// The network should be 'ip', 'ip4' or 'ip6', default network is 'ip'.
|
||||||
Resolve(ctx context.Context, network, host string) ([]net.IP, error)
|
Resolve(ctx context.Context, network, host string, opts ...Option) ([]net.IP, error)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user