github.com/annwntech/go-micro/v2@v2.9.5/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  type Option func(*Options)
    48  
    49  type RegisterOption func(*RegisterOptions)
    50  
    51  type WatchOption func(*WatchOptions)
    52  
    53  type DeregisterOption func(*DeregisterOptions)
    54  
    55  type GetOption func(*GetOptions)
    56  
    57  type ListOption func(*ListOptions)
    58  
    59  // Addrs is the registry addresses to use
    60  func Addrs(addrs ...string) Option {
    61  	return func(o *Options) {
    62  		o.Addrs = addrs
    63  	}
    64  }
    65  
    66  func Timeout(t time.Duration) Option {
    67  	return func(o *Options) {
    68  		o.Timeout = t
    69  	}
    70  }
    71  
    72  // Secure communication with the registry
    73  func Secure(b bool) Option {
    74  	return func(o *Options) {
    75  		o.Secure = b
    76  	}
    77  }
    78  
    79  // Specify TLS Config
    80  func TLSConfig(t *tls.Config) Option {
    81  	return func(o *Options) {
    82  		o.TLSConfig = t
    83  	}
    84  }
    85  
    86  func RegisterTTL(t time.Duration) RegisterOption {
    87  	return func(o *RegisterOptions) {
    88  		o.TTL = t
    89  	}
    90  }
    91  
    92  func RegisterContext(ctx context.Context) RegisterOption {
    93  	return func(o *RegisterOptions) {
    94  		o.Context = ctx
    95  	}
    96  }
    97  
    98  // Watch a service
    99  func WatchService(name string) WatchOption {
   100  	return func(o *WatchOptions) {
   101  		o.Service = name
   102  	}
   103  }
   104  
   105  func WatchContext(ctx context.Context) WatchOption {
   106  	return func(o *WatchOptions) {
   107  		o.Context = ctx
   108  	}
   109  }
   110  
   111  func DeregisterContext(ctx context.Context) DeregisterOption {
   112  	return func(o *DeregisterOptions) {
   113  		o.Context = ctx
   114  	}
   115  }
   116  
   117  func GetContext(ctx context.Context) GetOption {
   118  	return func(o *GetOptions) {
   119  		o.Context = ctx
   120  	}
   121  }
   122  
   123  func ListContext(ctx context.Context) ListOption {
   124  	return func(o *ListOptions) {
   125  		o.Context = ctx
   126  	}
   127  }