api/resolver: add resolve options (#1756)
* api/resolver: Resolve options * router/registry: fix init bug * router/registry: fix wildcard query bug * web: fix registation domain bug * registry/etcd: pass domain in service metadata * api/resolver/subdomain: expose domain func * Update api/resolver/subdomain/subdomain.go Co-authored-by: Dominic Wong <domwongemail@googlemail.com> Co-authored-by: Dominic Wong <domwongemail@googlemail.com>
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
type Options struct {
|
||||
Handler string
|
||||
Domain string
|
||||
ServicePrefix string
|
||||
}
|
||||
|
||||
@@ -19,13 +18,6 @@ func WithHandler(h string) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return func(o *Options) {
|
||||
@@ -39,6 +31,30 @@ func NewOptions(opts ...Option) Options {
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
// ResolveOptions are used when resolving a request
|
||||
type ResolveOptions struct {
|
||||
Domain string
|
||||
}
|
||||
|
||||
// ResolveOption sets an option
|
||||
type ResolveOption func(*ResolveOptions)
|
||||
|
||||
// Domain sets the resolve Domain option
|
||||
func Domain(n string) ResolveOption {
|
||||
return func(o *ResolveOptions) {
|
||||
o.Domain = n
|
||||
}
|
||||
}
|
||||
|
||||
// NewResolveOptions returns new initialised resolve options
|
||||
func NewResolveOptions(opts ...ResolveOption) ResolveOptions {
|
||||
var options ResolveOptions
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
if len(options.Domain) == 0 {
|
||||
options.Domain = registry.DefaultDomain
|
||||
}
|
||||
|
Reference in New Issue
Block a user