Dynamic Namespace

This commit is contained in:
Ben Toogood
2020-04-09 11:03:33 +01:00
parent 27eb7db1c2
commit 4ff959ef50
5 changed files with 31 additions and 9 deletions

View File

@@ -1,11 +1,22 @@
package resolver
import (
"net/http"
"github.com/micro/go-micro/v2/auth"
)
// 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(auth.DefaultNamespace)
}
return options
}
@@ -16,8 +27,8 @@ func WithHandler(h string) Option {
}
}
// WithNamespace sets the namespace being used
func WithNamespace(n string) Option {
// WithNamespace sets the function which determines the namespace for a request
func WithNamespace(n func(*http.Request) string) Option {
return func(o *Options) {
o.Namespace = n
}