micro/api/resolver/options.go

71 lines
1.3 KiB
Go
Raw Normal View History

2019-06-03 20:44:43 +03:00
package resolver
2020-04-09 13:03:33 +03:00
import (
"context"
"github.com/unistack-org/micro/v3/register"
2020-04-09 13:03:33 +03:00
)
// Options struct
type Options struct {
// Context is for external defined options
Context context.Context
// Handler name
Handler string
// ServicePrefix is the prefix
ServicePrefix string
2019-06-03 20:44:43 +03:00
}
// Option func
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
}
}
// WithServicePrefix sets the ServicePrefix option
func WithServicePrefix(p string) Option {
2019-06-03 20:44:43 +03:00
return func(o *Options) {
o.ServicePrefix = p
2019-06-03 20:44:43 +03:00
}
}
// 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: register.DefaultDomain}
for _, o := range opts {
o(&options)
}
return options
}