github.com/micro/go-micro/v2@v2.9.1/registry/options.go (about)

     1  package registry
     2  
     3  import (
     4  	"context"
     5  	"crypto/tls"
     6  	"time"
     7  )
     8  
     9  type Options struct {
    10  	Addrs     []string
    11  	Timeout   time.Duration
    12  	Secure    bool
    13  	TLSConfig *tls.Config
    14  	// Other options for implementations of the interface
    15  	// can be stored in a context
    16  	Context context.Context
    17  }
    18  
    19  type RegisterOptions struct {
    20  	TTL time.Duration
    21  	// Other options for implementations of the interface
    22  	// can be stored in a context
    23  	Context context.Context
    24  }
    25  
    26  type WatchOptions struct {
    27  	// Specify a service to watch
    28  	// If blank, the watch is for all services
    29  	Service string
    30  	// Other options for implementations of the interface
    31  	// can be stored in a context
    32  	Context context.Context
    33  }
    34  
    35  type DeregisterOptions struct {
    36  	Context context.Context
    37  }
    38  
    39  type GetOptions struct {
    40  	Context context.Context
    41  }
    42  
    43  type ListOptions struct {
    44  	Context context.Context
    45  }
    46  
    47  // Addrs is the registry addresses to use
    48  func Addrs(addrs ...string) Option {
    49  	return func(o *Options) {
    50  		o.Addrs = addrs
    51  	}
    52  }
    53  
    54  func Timeout(t time.Duration) Option {
    55  	return func(o *Options) {
    56  		o.Timeout = t
    57  	}
    58  }
    59  
    60  // Secure communication with the registry
    61  func Secure(b bool) Option {
    62  	return func(o *Options) {
    63  		o.Secure = b
    64  	}
    65  }
    66  
    67  // Specify TLS Config
    68  func TLSConfig(t *tls.Config) Option {
    69  	return func(o *Options) {
    70  		o.TLSConfig = t
    71  	}
    72  }
    73  
    74  func RegisterTTL(t time.Duration) RegisterOption {
    75  	return func(o *RegisterOptions) {
    76  		o.TTL = t
    77  	}
    78  }
    79  
    80  func RegisterContext(ctx context.Context) RegisterOption {
    81  	return func(o *RegisterOptions) {
    82  		o.Context = ctx
    83  	}
    84  }
    85  
    86  // Watch a service
    87  func WatchService(name string) WatchOption {
    88  	return func(o *WatchOptions) {
    89  		o.Service = name
    90  	}
    91  }
    92  
    93  func WatchContext(ctx context.Context) WatchOption {
    94  	return func(o *WatchOptions) {
    95  		o.Context = ctx
    96  	}
    97  }
    98  
    99  func DeregisterContext(ctx context.Context) DeregisterOption {
   100  	return func(o *DeregisterOptions) {
   101  		o.Context = ctx
   102  	}
   103  }
   104  
   105  func GetContext(ctx context.Context) GetOption {
   106  	return func(o *GetOptions) {
   107  		o.Context = ctx
   108  	}
   109  }
   110  
   111  func ListContext(ctx context.Context) ListOption {
   112  	return func(o *ListOptions) {
   113  		o.Context = ctx
   114  	}
   115  }