diff --git a/admission/admission.go b/admission/admission.go index 5c9c546..48b9f42 100644 --- a/admission/admission.go +++ b/admission/admission.go @@ -101,7 +101,7 @@ func NewAdmission(opts ...Option) admission.Admission { return p } -func (p *localAdmission) Admit(ctx context.Context, addr string) bool { +func (p *localAdmission) Admit(ctx context.Context, addr string, opts ...admission.Option) bool { if addr == "" || p == nil { return true } diff --git a/admission/plugin.go b/admission/plugin.go index c2a246d..91ea9d9 100644 --- a/admission/plugin.go +++ b/admission/plugin.go @@ -46,7 +46,7 @@ func NewGRPCPlugin(name string, addr string, opts ...plugin.Option) admission.Ad return p } -func (p *grpcPlugin) Admit(ctx context.Context, addr string) bool { +func (p *grpcPlugin) Admit(ctx context.Context, addr string, opts ...admission.Option) bool { if p.client == nil { return false } @@ -102,7 +102,7 @@ func NewHTTPPlugin(name string, url string, opts ...plugin.Option) admission.Adm } } -func (p *httpPlugin) Admit(ctx context.Context, addr string) (ok bool) { +func (p *httpPlugin) Admit(ctx context.Context, addr string, opts ...admission.Option) (ok bool) { if p.client == nil { return } diff --git a/auth/auth.go b/auth/auth.go index 49f7be9..60c6e98 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -97,7 +97,7 @@ func NewAuthenticator(opts ...Option) auth.Authenticator { } // Authenticate checks the validity of the provided user-password pair. -func (p *authenticator) Authenticate(ctx context.Context, user, password string) (string, bool) { +func (p *authenticator) Authenticate(ctx context.Context, user, password string, opts ...auth.Option) (string, bool) { if p == nil { return "", true } diff --git a/auth/plugin.go b/auth/plugin.go index b53885e..d3246f5 100644 --- a/auth/plugin.go +++ b/auth/plugin.go @@ -49,7 +49,7 @@ func NewGRPCPlugin(name string, addr string, opts ...plugin.Option) auth.Authent } // Authenticate checks the validity of the provided user-password pair. -func (p *grpcPlugin) Authenticate(ctx context.Context, user, password string) (string, bool) { +func (p *grpcPlugin) Authenticate(ctx context.Context, user, password string, opts ...auth.Option) (string, bool) { if p.client == nil { return "", false } @@ -110,7 +110,7 @@ func NewHTTPPlugin(name string, url string, opts ...plugin.Option) auth.Authenti } } -func (p *httpPlugin) Authenticate(ctx context.Context, user, password string) (id string, ok bool) { +func (p *httpPlugin) Authenticate(ctx context.Context, user, password string, opts ...auth.Option) (id string, ok bool) { if p.client == nil { return } diff --git a/hosts/hosts.go b/hosts/hosts.go index b06f789..0d48978 100644 --- a/hosts/hosts.go +++ b/hosts/hosts.go @@ -104,7 +104,7 @@ func NewHostMapper(opts ...Option) hosts.HostMapper { // Lookup searches the IP address corresponds to the given network and host from the host table. // The network should be 'ip', 'ip4' or 'ip6', default network is 'ip'. // the host should be a hostname (example.org) or a hostname with dot prefix (.example.org). -func (h *hostMapper) Lookup(ctx context.Context, network, host string) (ips []net.IP, ok bool) { +func (h *hostMapper) Lookup(ctx context.Context, network, host string, opts ...hosts.Option) (ips []net.IP, ok bool) { h.options.logger.Debugf("lookup %s/%s", host, network) ips = h.lookup(host) if ips == nil { diff --git a/hosts/plugin.go b/hosts/plugin.go index e1d56e1..1752d28 100644 --- a/hosts/plugin.go +++ b/hosts/plugin.go @@ -47,7 +47,7 @@ func NewGRPCPlugin(name string, addr string, opts ...plugin.Option) hosts.HostMa return p } -func (p *grpcPlugin) Lookup(ctx context.Context, network, host string) (ips []net.IP, ok bool) { +func (p *grpcPlugin) Lookup(ctx context.Context, network, host string, opts ...hosts.Option) (ips []net.IP, ok bool) { p.log.Debugf("lookup %s/%s", host, network) if p.client == nil { @@ -116,7 +116,7 @@ func NewHTTPPlugin(name string, url string, opts ...plugin.Option) hosts.HostMap } } -func (p *httpPlugin) Lookup(ctx context.Context, network, host string) (ips []net.IP, ok bool) { +func (p *httpPlugin) Lookup(ctx context.Context, network, host string, opts ...hosts.Option) (ips []net.IP, ok bool) { p.log.Debugf("lookup %s/%s", host, network) if p.client == nil { diff --git a/ingress/ingress.go b/ingress/ingress.go index 8cb421e..5bbf94b 100644 --- a/ingress/ingress.go +++ b/ingress/ingress.go @@ -219,7 +219,7 @@ func (ing *localIngress) parseRules(r io.Reader) (rules []Rule, err error) { return } -func (ing *localIngress) Get(ctx context.Context, host string) string { +func (ing *localIngress) Get(ctx context.Context, host string, opts ...ingress.GetOption) string { if host == "" || ing == nil { return "" } @@ -259,7 +259,7 @@ func (ing *localIngress) Get(ctx context.Context, host string) string { return ep } -func (ing *localIngress) Set(ctx context.Context, host, endpoint string) { +func (ing *localIngress) Set(ctx context.Context, host, endpoint string, opts ...ingress.SetOption) { } diff --git a/ingress/plugin.go b/ingress/plugin.go index 406b72c..b41a0ae 100644 --- a/ingress/plugin.go +++ b/ingress/plugin.go @@ -46,7 +46,7 @@ func NewGRPCPlugin(name string, addr string, opts ...plugin.Option) ingress.Ingr return p } -func (p *grpcPlugin) Get(ctx context.Context, host string) string { +func (p *grpcPlugin) Get(ctx context.Context, host string, opts ...ingress.GetOption) string { if p.client == nil { return "" } @@ -62,7 +62,7 @@ func (p *grpcPlugin) Get(ctx context.Context, host string) string { return r.GetEndpoint() } -func (p *grpcPlugin) Set(ctx context.Context, host, endpoint string) { +func (p *grpcPlugin) Set(ctx context.Context, host, endpoint string, opts ...ingress.SetOption) { if p.client == nil { return } @@ -121,7 +121,7 @@ func NewHTTPPlugin(name string, url string, opts ...plugin.Option) ingress.Ingre } } -func (p *httpPlugin) Get(ctx context.Context, host string) (endpoint string) { +func (p *httpPlugin) Get(ctx context.Context, host string, opts ...ingress.GetOption) (endpoint string) { if p.client == nil { return } @@ -160,7 +160,7 @@ func (p *httpPlugin) Get(ctx context.Context, host string) (endpoint string) { return res.Endpoint } -func (p *httpPlugin) Set(ctx context.Context, host, endpoint string) { +func (p *httpPlugin) Set(ctx context.Context, host, endpoint string, opts ...ingress.SetOption) { if p.client == nil { return } diff --git a/recorder/file.go b/recorder/file.go index c0651c9..cbd4c90 100644 --- a/recorder/file.go +++ b/recorder/file.go @@ -37,7 +37,7 @@ func FileRecorder(filename string, opts ...FileRecorderOption) recorder.Recorder } } -func (r *fileRecorder) Record(ctx context.Context, b []byte) error { +func (r *fileRecorder) Record(ctx context.Context, b []byte, opts ...recorder.RecordOption) error { f, err := os.OpenFile(r.filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) if err != nil { return err diff --git a/recorder/http.go b/recorder/http.go index efea5c3..a255cc2 100644 --- a/recorder/http.go +++ b/recorder/http.go @@ -42,7 +42,7 @@ func HTTPRecorder(url string, opts ...HTTPRecorderOption) recorder.Recorder { } } -func (r *httpRecorder) Record(ctx context.Context, b []byte) error { +func (r *httpRecorder) Record(ctx context.Context, b []byte, opts ...recorder.RecordOption) error { req, err := http.NewRequest(http.MethodPost, r.url, bytes.NewReader(b)) if err != nil { return err diff --git a/recorder/plugin.go b/recorder/plugin.go index 456d1d2..9b74327 100644 --- a/recorder/plugin.go +++ b/recorder/plugin.go @@ -48,7 +48,7 @@ func NewGRPCPlugin(name string, addr string, opts ...plugin.Option) recorder.Rec return p } -func (p *grpcPlugin) Record(ctx context.Context, b []byte) error { +func (p *grpcPlugin) Record(ctx context.Context, b []byte, opts ...recorder.RecordOption) error { if p.client == nil { return nil } @@ -98,13 +98,13 @@ func NewHTTPPlugin(name string, url string, opts ...plugin.Option) recorder.Reco client: plugin.NewHTTPClient(&options), header: options.Header, log: logger.Default().WithFields(map[string]any{ - "kind": "recorder", + "kind": "recorder", "recorder": name, }), } } -func (p *httpPlugin) Record(ctx context.Context, b []byte) error { +func (p *httpPlugin) Record(ctx context.Context, b []byte, opts ...recorder.RecordOption) error { if len(b) == 0 || p.client == nil { return nil } diff --git a/recorder/redis.go b/recorder/redis.go index 2c4749d..9df42e7 100644 --- a/recorder/redis.go +++ b/recorder/redis.go @@ -54,7 +54,7 @@ func RedisSetRecorder(addr string, opts ...RedisRecorderOption) recorder.Recorde } } -func (r *redisSetRecorder) Record(ctx context.Context, b []byte) error { +func (r *redisSetRecorder) Record(ctx context.Context, b []byte, opts ...recorder.RecordOption) error { if r.key == "" { return nil } @@ -88,7 +88,7 @@ func RedisListRecorder(addr string, opts ...RedisRecorderOption) recorder.Record } } -func (r *redisListRecorder) Record(ctx context.Context, b []byte) error { +func (r *redisListRecorder) Record(ctx context.Context, b []byte, opts ...recorder.RecordOption) error { if r.key == "" { return nil } @@ -122,7 +122,7 @@ func RedisSortedSetRecorder(addr string, opts ...RedisRecorderOption) recorder.R } } -func (r *redisSortedSetRecorder) Record(ctx context.Context, b []byte) error { +func (r *redisSortedSetRecorder) Record(ctx context.Context, b []byte, opts ...recorder.RecordOption) error { if r.key == "" { return nil } diff --git a/recorder/tcp.go b/recorder/tcp.go index ea4b124..1c318c7 100644 --- a/recorder/tcp.go +++ b/recorder/tcp.go @@ -40,7 +40,7 @@ func TCPRecorder(addr string, opts ...TCPRecorderOption) recorder.Recorder { } } -func (r *tcpRecorder) Record(ctx context.Context, b []byte) error { +func (r *tcpRecorder) Record(ctx context.Context, b []byte, opts ...recorder.RecordOption) error { c, err := r.dialer.DialContext(ctx, "tcp", r.addr) if err != nil { return err diff --git a/registry/admission.go b/registry/admission.go index 10b96bf..5438614 100644 --- a/registry/admission.go +++ b/registry/admission.go @@ -30,10 +30,10 @@ type admissionWrapper struct { r *admissionRegistry } -func (w *admissionWrapper) Admit(ctx context.Context, addr string) bool { +func (w *admissionWrapper) Admit(ctx context.Context, addr string, opts ...admission.Option) bool { p := w.r.get(w.name) if p == nil { return false } - return p.Admit(ctx, addr) + return p.Admit(ctx, addr, opts...) } diff --git a/registry/auther.go b/registry/auther.go index ae76aff..dd39f16 100644 --- a/registry/auther.go +++ b/registry/auther.go @@ -30,10 +30,10 @@ type autherWrapper struct { r *autherRegistry } -func (w *autherWrapper) Authenticate(ctx context.Context, user, password string) (string, bool) { +func (w *autherWrapper) Authenticate(ctx context.Context, user, password string, opts ...auth.Option) (string, bool) { v := w.r.get(w.name) if v == nil { return "", true } - return v.Authenticate(ctx, user, password) + return v.Authenticate(ctx, user, password, opts...) } diff --git a/registry/hosts.go b/registry/hosts.go index e678931..9079646 100644 --- a/registry/hosts.go +++ b/registry/hosts.go @@ -31,10 +31,10 @@ type hostsWrapper struct { r *hostsRegistry } -func (w *hostsWrapper) Lookup(ctx context.Context, network, host string) ([]net.IP, bool) { +func (w *hostsWrapper) Lookup(ctx context.Context, network, host string, opts ...hosts.Option) ([]net.IP, bool) { v := w.r.get(w.name) if v == nil { return nil, false } - return v.Lookup(ctx, network, host) + return v.Lookup(ctx, network, host, opts...) } diff --git a/registry/ingress.go b/registry/ingress.go index 72afd90..ce68ef0 100644 --- a/registry/ingress.go +++ b/registry/ingress.go @@ -30,19 +30,19 @@ type ingressWrapper struct { r *ingressRegistry } -func (w *ingressWrapper) Get(ctx context.Context, host string) string { +func (w *ingressWrapper) Get(ctx context.Context, host string, opts ...ingress.GetOption) string { v := w.r.get(w.name) if v == nil { return "" } - return v.Get(ctx, host) + return v.Get(ctx, host, opts...) } -func (w *ingressWrapper) Set(ctx context.Context, host, endpoint string) { +func (w *ingressWrapper) Set(ctx context.Context, host, endpoint string, opts ...ingress.SetOption) { v := w.r.get(w.name) if v == nil { return } - v.Set(ctx, host, endpoint) + v.Set(ctx, host, endpoint, opts...) } diff --git a/registry/recorder.go b/registry/recorder.go index 27b28f9..9812709 100644 --- a/registry/recorder.go +++ b/registry/recorder.go @@ -30,10 +30,10 @@ type recorderWrapper struct { r *recorderRegistry } -func (w *recorderWrapper) Record(ctx context.Context, b []byte) error { +func (w *recorderWrapper) Record(ctx context.Context, b []byte, opts ...recorder.RecordOption) error { v := w.r.get(w.name) if v == nil { return nil } - return v.Record(ctx, b) + return v.Record(ctx, b, opts...) } diff --git a/registry/resolver.go b/registry/resolver.go index dff7e26..63f2131 100644 --- a/registry/resolver.go +++ b/registry/resolver.go @@ -31,10 +31,10 @@ type resolverWrapper struct { r *resolverRegistry } -func (w *resolverWrapper) Resolve(ctx context.Context, network, host string) ([]net.IP, error) { +func (w *resolverWrapper) Resolve(ctx context.Context, network, host string, opts ...resolver.Option) ([]net.IP, error) { r := w.r.get(w.name) if r == nil { return nil, resolver.ErrInvalid } - return r.Resolve(ctx, network, host) + return r.Resolve(ctx, network, host, opts...) } diff --git a/resolver/plugin.go b/resolver/plugin.go index 60c02be..dacb293 100644 --- a/resolver/plugin.go +++ b/resolver/plugin.go @@ -13,8 +13,8 @@ import ( "github.com/go-gost/core/logger" "github.com/go-gost/core/resolver" "github.com/go-gost/plugin/resolver/proto" - auth_util "github.com/go-gost/x/internal/util/auth" "github.com/go-gost/x/internal/plugin" + auth_util "github.com/go-gost/x/internal/util/auth" "google.golang.org/grpc" ) @@ -49,7 +49,7 @@ func NewGRPCPlugin(name string, addr string, opts ...plugin.Option) (resolver.Re return p, nil } -func (p *grpcPlugin) Resolve(ctx context.Context, network, host string) (ips []net.IP, err error) { +func (p *grpcPlugin) Resolve(ctx context.Context, network, host string, opts ...resolver.Option) (ips []net.IP, err error) { p.log.Debugf("resolve %s/%s", host, network) if p.client == nil { @@ -117,7 +117,7 @@ func NewHTTPPlugin(name string, url string, opts ...plugin.Option) resolver.Reso } } -func (p *httpPlugin) Resolve(ctx context.Context, network, host string) (ips []net.IP, err error) { +func (p *httpPlugin) Resolve(ctx context.Context, network, host string, opts ...resolver.Option) (ips []net.IP, err error) { p.log.Debugf("resolve %s/%s", host, network) if p.client == nil { diff --git a/resolver/resolver.go b/resolver/resolver.go index b6e3aca..66ff437 100644 --- a/resolver/resolver.go +++ b/resolver/resolver.go @@ -91,7 +91,7 @@ func NewResolver(nameservers []NameServer, opts ...Option) (resolver.Resolver, e }, nil } -func (r *localResolver) Resolve(ctx context.Context, network, host string) (ips []net.IP, err error) { +func (r *localResolver) Resolve(ctx context.Context, network, host string, opts ...resolver.Option) (ips []net.IP, err error) { if ip := net.ParseIP(host); ip != nil { return []net.IP{ip}, nil }