github.com/searKing/golang/go@v1.2.74/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 //go:generate go-option -type "Pick" 19 type Pick struct{} 20 21 // Picker is used to pick an Address. 22 type Picker interface { 23 Pick(ctx context.Context, addrs []Address, opts ...PickOption) (Address, error) 24 } 25 26 // The PickerFunc type is an adapter to allow the use of 27 // ordinary functions as Picker handlers. If f is a function 28 // with the appropriate signature, PickerFunc(f) is a 29 // Handler that calls f. 30 type PickerFunc func(ctx context.Context, addrs []Address, opts ...PickOption) (Address, error) 31 32 // Pick calls f(ctx, addrs, opts...). 33 func (f PickerFunc) Pick(ctx context.Context, addrs []Address, opts ...PickOption) (Address, error) { 34 return f(ctx, addrs, opts...) 35 }