micro/api/resolver/options.go
Vasiliy Tolstov 8b7380876e modify all code for never logger interface
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2021-01-10 19:24:03 +03:00

68 lines
1.3 KiB
Go

package resolver
import (
"context"
"github.com/unistack-org/micro/v3/registry"
)
// Options struct
type Options struct {
Handler string
ServicePrefix string
Context context.Context
}
// Option func
type Option func(o *Options)
// WithHandler sets the handler being used
func WithHandler(h string) Option {
return func(o *Options) {
o.Handler = h
}
}
// WithServicePrefix sets the ServicePrefix option
func WithServicePrefix(p string) Option {
return func(o *Options) {
o.ServicePrefix = p
}
}
// NewOptions returns new initialised options
func NewOptions(opts ...Option) Options {
options := Options{
Context: context.Background(),
}
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 {
options := ResolveOptions{Domain: registry.DefaultDomain}
for _, o := range opts {
o(&options)
}
return options
}