github.com/searKing/golang/go@v1.2.117/net/resolver/picker.go (about)

     1  // Copyright 2021 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package resolver
     6  
     7  import (
     8  	"context"
     9  	"errors"
    10  )
    11  
    12  var (
    13  	// ErrNoAddrAvailable indicates no Addr is available for pick().
    14  	ErrNoAddrAvailable = errors.New("no Addr is available")
    15  )
    16  
    17  // Pick includes additional information for Pick.
    18  //
    19  //go:generate go-option -type "Pick"
    20  type Pick struct{}
    21  
    22  // Picker is used to pick an Address.
    23  type Picker interface {
    24  	Pick(ctx context.Context, addrs []Address, opts ...PickOption) (Address, error)
    25  }
    26  
    27  // The PickerFunc type is an adapter to allow the use of
    28  // ordinary functions as Picker handlers. If f is a function
    29  // with the appropriate signature, PickerFunc(f) is a
    30  // Handler that calls f.
    31  type PickerFunc func(ctx context.Context, addrs []Address, opts ...PickOption) (Address, error)
    32  
    33  // Pick calls f(ctx, addrs, opts...).
    34  func (f PickerFunc) Pick(ctx context.Context, addrs []Address, opts ...PickOption) (Address, error) {
    35  	return f(ctx, addrs, opts...)
    36  }