2019-06-03 19:44:43 +02:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
2021-10-12 13:55:53 +02:00
|
|
|
"go-micro.dev/v4/api/resolver"
|
|
|
|
"go-micro.dev/v4/api/resolver/vpath"
|
2022-09-29 16:44:53 +02:00
|
|
|
"go-micro.dev/v4/logger"
|
2021-10-12 13:55:53 +02:00
|
|
|
"go-micro.dev/v4/registry"
|
2019-06-03 19:44:43 +02:00
|
|
|
)
|
|
|
|
|
2022-10-01 10:50:11 +02:00
|
|
|
// Options is a struct of options available.
|
2019-06-03 19:44:43 +02:00
|
|
|
type Options struct {
|
2020-04-08 16:39:01 +02:00
|
|
|
Registry registry.Registry
|
|
|
|
Resolver resolver.Resolver
|
2022-09-29 16:44:53 +02:00
|
|
|
Logger logger.Logger
|
2023-04-26 02:16:34 +02:00
|
|
|
Handler string
|
2019-06-03 19:44:43 +02:00
|
|
|
}
|
|
|
|
|
2022-10-01 10:50:11 +02:00
|
|
|
// Option is a helper for a single options.
|
2019-06-03 19:44:43 +02:00
|
|
|
type Option func(o *Options)
|
|
|
|
|
2022-10-01 10:50:11 +02:00
|
|
|
// NewOptions wires options together.
|
2019-06-03 19:44:43 +02:00
|
|
|
func NewOptions(opts ...Option) Options {
|
|
|
|
options := Options{
|
|
|
|
Handler: "meta",
|
2019-12-30 19:29:20 +02:00
|
|
|
Registry: registry.DefaultRegistry,
|
2022-09-29 16:44:53 +02:00
|
|
|
Logger: logger.DefaultLogger,
|
2019-06-03 19:44:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, o := range opts {
|
|
|
|
o(&options)
|
|
|
|
}
|
|
|
|
|
2020-04-09 11:34:21 +02:00
|
|
|
if options.Resolver == nil {
|
|
|
|
options.Resolver = vpath.NewResolver(
|
|
|
|
resolver.WithHandler(options.Handler),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-06-03 19:44:43 +02:00
|
|
|
return options
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithHandler(h string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Handler = h
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithRegistry(r registry.Registry) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Registry = r
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithResolver(r resolver.Resolver) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Resolver = r
|
|
|
|
}
|
|
|
|
}
|
2022-09-29 16:44:53 +02:00
|
|
|
|
2022-09-30 16:27:07 +02:00
|
|
|
// WithLogger sets the underline logger.
|
2022-09-29 16:44:53 +02:00
|
|
|
func WithLogger(l logger.Logger) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Logger = l
|
|
|
|
}
|
|
|
|
}
|