2019-06-03 20:44:43 +03:00
|
|
|
package resolver
|
|
|
|
|
2020-04-09 13:03:33 +03:00
|
|
|
import (
|
2020-06-26 16:28:18 +03:00
|
|
|
"github.com/micro/go-micro/v2/registry"
|
2020-04-09 13:03:33 +03:00
|
|
|
)
|
|
|
|
|
2020-06-26 16:28:18 +03:00
|
|
|
type Options struct {
|
|
|
|
Handler string
|
|
|
|
Domain string
|
|
|
|
ServicePrefix string
|
2019-06-03 20:44:43 +03:00
|
|
|
}
|
|
|
|
|
2020-06-26 16:28:18 +03:00
|
|
|
type Option func(o *Options)
|
|
|
|
|
2019-06-03 20:44:43 +03:00
|
|
|
// WithHandler sets the handler being used
|
|
|
|
func WithHandler(h string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Handler = h
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-26 16:28:18 +03:00
|
|
|
// WithDomain sets the namespace option
|
|
|
|
func WithDomain(n string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Domain = n
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithServicePrefix sets the ServicePrefix option
|
|
|
|
func WithServicePrefix(p string) Option {
|
2019-06-03 20:44:43 +03:00
|
|
|
return func(o *Options) {
|
2020-06-26 16:28:18 +03:00
|
|
|
o.ServicePrefix = p
|
2019-06-03 20:44:43 +03:00
|
|
|
}
|
|
|
|
}
|
2020-06-26 16:28:18 +03:00
|
|
|
|
|
|
|
// NewOptions returns new initialised options
|
|
|
|
func NewOptions(opts ...Option) Options {
|
|
|
|
var options Options
|
|
|
|
for _, o := range opts {
|
|
|
|
o(&options)
|
|
|
|
}
|
|
|
|
if len(options.Domain) == 0 {
|
|
|
|
options.Domain = registry.DefaultDomain
|
|
|
|
}
|
|
|
|
|
|
|
|
return options
|
|
|
|
}
|