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:
ben-toogood
2020-06-26 14:28:18 +01:00
committed by GitHub
parent 4f0f4326df
commit 104b7d8f8d
10 changed files with 211 additions and 44 deletions

View File

@@ -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
}