2019-06-03 18:44:43 +01:00
|
|
|
package resolver
|
|
|
|
|
2020-04-09 11:03:33 +01:00
|
|
|
import (
|
2021-01-10 19:24:03 +03:00
|
|
|
"context"
|
|
|
|
|
2021-10-02 19:55:07 +03:00
|
|
|
"go.unistack.org/micro/v3/register"
|
2020-04-09 11:03:33 +01:00
|
|
|
)
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// Options struct
|
2020-06-26 14:28:18 +01:00
|
|
|
type Options struct {
|
2021-03-06 19:45:13 +03:00
|
|
|
// Context is for external defined options
|
|
|
|
Context context.Context
|
|
|
|
// Handler name
|
|
|
|
Handler string
|
|
|
|
// ServicePrefix is the prefix
|
2020-06-26 14:28:18 +01:00
|
|
|
ServicePrefix string
|
2019-06-03 18:44:43 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// Option func
|
2020-06-26 14:28:18 +01:00
|
|
|
type Option func(o *Options)
|
|
|
|
|
2019-06-03 18:44:43 +01:00
|
|
|
// WithHandler sets the handler being used
|
|
|
|
func WithHandler(h string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Handler = h
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-26 14:28:18 +01:00
|
|
|
// WithServicePrefix sets the ServicePrefix option
|
|
|
|
func WithServicePrefix(p string) Option {
|
2019-06-03 18:44:43 +01:00
|
|
|
return func(o *Options) {
|
2020-06-26 14:28:18 +01:00
|
|
|
o.ServicePrefix = p
|
2019-06-03 18:44:43 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-26 14:28:18 +01:00
|
|
|
|
|
|
|
// NewOptions returns new initialised options
|
|
|
|
func NewOptions(opts ...Option) Options {
|
2021-01-10 19:24:03 +03:00
|
|
|
options := Options{
|
|
|
|
Context: context.Background(),
|
|
|
|
}
|
2020-06-26 14:28:18 +01:00
|
|
|
for _, o := range opts {
|
|
|
|
o(&options)
|
|
|
|
}
|
2020-06-29 16:37:45 +01:00
|
|
|
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 {
|
2021-01-29 13:17:32 +03:00
|
|
|
options := ResolveOptions{Domain: register.DefaultDomain}
|
2020-06-29 16:37:45 +01:00
|
|
|
for _, o := range opts {
|
|
|
|
o(&options)
|
|
|
|
}
|
2020-06-26 14:28:18 +01:00
|
|
|
|
|
|
|
return options
|
|
|
|
}
|