api/resolver: update resolver to enable subdomain routing (#1747)
* api/resolver: update domain / service prefix usage * api/resolver/subdomain: implement subdomain resolver for domain resolution * api/handler: fix tests
This commit is contained in:
@@ -1,23 +1,17 @@
|
||||
package resolver
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"github.com/micro/go-micro/v2/registry"
|
||||
)
|
||||
|
||||
// NewOptions returns new initialised options
|
||||
func NewOptions(opts ...Option) Options {
|
||||
var options Options
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
if options.Namespace == nil {
|
||||
options.Namespace = StaticNamespace("go.micro")
|
||||
}
|
||||
|
||||
return options
|
||||
type Options struct {
|
||||
Handler string
|
||||
Domain string
|
||||
ServicePrefix string
|
||||
}
|
||||
|
||||
type Option func(o *Options)
|
||||
|
||||
// WithHandler sets the handler being used
|
||||
func WithHandler(h string) Option {
|
||||
return func(o *Options) {
|
||||
@@ -25,9 +19,29 @@ func WithHandler(h string) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// WithNamespace sets the function which determines the namespace for a request
|
||||
func WithNamespace(n func(*http.Request) string) Option {
|
||||
// WithDomain sets the namespace option
|
||||
func WithDomain(n string) Option {
|
||||
return func(o *Options) {
|
||||
o.Namespace = n
|
||||
o.Domain = n
|
||||
}
|
||||
}
|
||||
|
||||
// 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 {
|
||||
var options Options
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
if len(options.Domain) == 0 {
|
||||
options.Domain = registry.DefaultDomain
|
||||
}
|
||||
|
||||
return options
|
||||
}
|
||||
|
Reference in New Issue
Block a user