feat: only check preferred/fallback protocols availability
This commit is contained in:
@ -15,6 +15,22 @@ func (r *Registry) Register(identifier Identifier, factory ProtocolFactory) {
|
||||
r.protocols[identifier] = factory
|
||||
}
|
||||
|
||||
func (r *Registry) Get(identifier Identifier, funcs ...ProtocolOptionFunc) (Protocol, error) {
|
||||
factory, exists := r.protocols[identifier]
|
||||
if !exists {
|
||||
return nil, errors.WithStack(ErrNotFound)
|
||||
}
|
||||
|
||||
protocolOpts := NewProtocolOptions(funcs...)
|
||||
|
||||
proto, err := factory(protocolOpts)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return proto, nil
|
||||
}
|
||||
|
||||
func (r *Registry) Availables(ctx context.Context, addr string, timeout time.Duration, funcs ...ProtocolOptionFunc) ([]Protocol, error) {
|
||||
availables := make([]Protocol, 0)
|
||||
protocolOpts := NewProtocolOptions(funcs...)
|
||||
|
Reference in New Issue
Block a user