238a0b95b7
Upgrade github.com/go-gost/core from v0.3.3 to v0.4.0, adapting to interface changes: - Admit(ctx, network, addr, opts) now accepts a network parameter - Router.Dial now accepts variadic chain.DialOption, forwarded to the route's Dial call along with router-level options - gRPC/HTTP admission plugins include the new Network field Also fix two typos: ResoloverNodeOption -> ResolverNodeOption, WithHostOpton -> WithHostOption.
40 lines
795 B
Go
40 lines
795 B
Go
package registry
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/go-gost/core/admission"
|
|
)
|
|
|
|
type admissionRegistry struct {
|
|
registry[admission.Admission]
|
|
}
|
|
|
|
func (r *admissionRegistry) Register(name string, v admission.Admission) error {
|
|
return r.registry.Register(name, v)
|
|
}
|
|
|
|
func (r *admissionRegistry) Get(name string) admission.Admission {
|
|
if name != "" {
|
|
return &admissionWrapper{name: name, r: r}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (r *admissionRegistry) get(name string) admission.Admission {
|
|
return r.registry.Get(name)
|
|
}
|
|
|
|
type admissionWrapper struct {
|
|
name string
|
|
r *admissionRegistry
|
|
}
|
|
|
|
func (w *admissionWrapper) Admit(ctx context.Context, network, addr string, opts ...admission.Option) bool {
|
|
p := w.r.get(w.name)
|
|
if p == nil {
|
|
return false
|
|
}
|
|
return p.Admit(ctx, network, addr, opts...)
|
|
}
|