add auther api

This commit is contained in:
ginuerzh
2022-02-12 14:12:09 +08:00
parent 345338d410
commit fdd67a6086
10 changed files with 293 additions and 13 deletions

View File

@ -18,8 +18,11 @@ type autherRegistry struct {
m sync.Map
}
func (r *autherRegistry) Register(name string, auth auth.Authenticator) error {
if _, loaded := r.m.LoadOrStore(name, auth); loaded {
func (r *autherRegistry) Register(name string, auther auth.Authenticator) error {
if name == "" || auther == nil {
return nil
}
if _, loaded := r.m.LoadOrStore(name, auther); loaded {
return ErrDup
}

View File

@ -19,6 +19,9 @@ type bypassRegistry struct {
}
func (r *bypassRegistry) Register(name string, bypass bypass.Bypass) error {
if name == "" || bypass == nil {
return nil
}
if _, loaded := r.m.LoadOrStore(name, bypass); loaded {
return ErrDup
}

View File

@ -19,6 +19,9 @@ type chainRegistry struct {
}
func (r *chainRegistry) Register(name string, chain chain.Chainer) error {
if name == "" || chain == nil {
return nil
}
if _, loaded := r.m.LoadOrStore(name, chain); loaded {
return ErrDup
}

View File

@ -20,6 +20,9 @@ type hostsRegistry struct {
}
func (r *hostsRegistry) Register(name string, hosts hosts.HostMapper) error {
if name == "" || hosts == nil {
return nil
}
if _, loaded := r.m.LoadOrStore(name, hosts); loaded {
return ErrDup
}

View File

@ -21,6 +21,9 @@ type resolverRegistry struct {
}
func (r *resolverRegistry) Register(name string, resolver resolver.Resolver) error {
if name == "" || resolver == nil {
return nil
}
if _, loaded := r.m.LoadOrStore(name, resolver); loaded {
return ErrDup
}

View File

@ -19,6 +19,9 @@ type serviceRegistry struct {
}
func (r *serviceRegistry) Register(name string, svc *service.Service) error {
if name == "" || svc == nil {
return nil
}
if _, loaded := r.m.LoadOrStore(name, svc); loaded {
return ErrDup
}