micro/registry/options.go

74 lines
1.3 KiB
Go
Raw Normal View History

2015-12-19 21:28:08 +03:00
package registry
import (
2018-03-03 14:53:52 +03:00
"context"
2016-01-17 02:39:47 +03:00
"crypto/tls"
2015-12-19 21:28:08 +03:00
"time"
)
type Options struct {
2016-03-16 01:20:21 +03:00
Addrs []string
2016-01-17 02:39:47 +03:00
Timeout time.Duration
Secure bool
TLSConfig *tls.Config
// Other options for implementations of the interface
// can be stored in a context
Context context.Context
2015-12-19 21:28:08 +03:00
}
2016-01-27 02:32:27 +03:00
type RegisterOptions struct {
TTL time.Duration
// Other options for implementations of the interface
// can be stored in a context
Context context.Context
}
2018-02-19 20:12:37 +03:00
type WatchOptions struct {
// Specify a service to watch
// If blank, the watch is for all services
Service string
// Other options for implementations of the interface
// can be stored in a context
Context context.Context
}
2016-03-16 01:20:21 +03:00
// Addrs is the registry addresses to use
func Addrs(addrs ...string) Option {
return func(o *Options) {
o.Addrs = addrs
}
}
2015-12-19 21:28:08 +03:00
func Timeout(t time.Duration) Option {
return func(o *Options) {
o.Timeout = t
}
}
2016-01-16 23:25:18 +03:00
// Secure communication with the registry
func Secure(b bool) Option {
return func(o *Options) {
o.Secure = b
}
}
2016-01-17 02:39:47 +03:00
// Specify TLS Config
func TLSConfig(t *tls.Config) Option {
return func(o *Options) {
o.TLSConfig = t
}
}
2016-01-27 02:32:27 +03:00
2016-01-27 15:23:18 +03:00
func RegisterTTL(t time.Duration) RegisterOption {
2016-01-27 02:32:27 +03:00
return func(o *RegisterOptions) {
o.TTL = t
}
}
2018-02-19 20:12:37 +03:00
// Watch a service
func WatchService(name string) WatchOption {
return func(o *WatchOptions) {
o.Service = name
}
}