server: register in the services namespace (#1718)
This commit is contained in:
parent
83cecdb294
commit
c16f4b741c
@ -278,7 +278,7 @@ var (
|
|||||||
Name: "service_namespace",
|
Name: "service_namespace",
|
||||||
EnvVars: []string{"MICRO_NAMESPACE"},
|
EnvVars: []string{"MICRO_NAMESPACE"},
|
||||||
Usage: "Namespace the service is operating in",
|
Usage: "Namespace the service is operating in",
|
||||||
Value: "go.micro",
|
Value: "micro",
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "auth_public_key",
|
Name: "auth_public_key",
|
||||||
@ -630,8 +630,9 @@ func (c *cmd) Before(ctx *cli.Context) error {
|
|||||||
if len(ctx.String("auth_private_key")) > 0 {
|
if len(ctx.String("auth_private_key")) > 0 {
|
||||||
authOpts = append(authOpts, auth.PrivateKey(ctx.String("auth_private_key")))
|
authOpts = append(authOpts, auth.PrivateKey(ctx.String("auth_private_key")))
|
||||||
}
|
}
|
||||||
if len(ctx.String("service_namespace")) > 0 {
|
if ns := ctx.String("service_namespace"); len(ns) > 0 {
|
||||||
authOpts = append(authOpts, auth.Issuer(ctx.String("service_namespace")))
|
serverOpts = append(serverOpts, server.Namespace(ns))
|
||||||
|
authOpts = append(authOpts, auth.Issuer(ns))
|
||||||
}
|
}
|
||||||
if name := ctx.String("auth_provider"); len(name) > 0 {
|
if name := ctx.String("auth_provider"); len(name) > 0 {
|
||||||
p, ok := DefaultAuthProviders[name]
|
p, ok := DefaultAuthProviders[name]
|
||||||
|
@ -576,8 +576,12 @@ func (g *grpcServer) Register() error {
|
|||||||
var regErr error
|
var regErr error
|
||||||
|
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
// set the ttl
|
// set the ttl and namespace
|
||||||
rOpts := []registry.RegisterOption{registry.RegisterTTL(config.RegisterTTL)}
|
rOpts := []registry.RegisterOption{
|
||||||
|
registry.RegisterTTL(config.RegisterTTL),
|
||||||
|
registry.RegisterDomain(g.opts.Namespace),
|
||||||
|
}
|
||||||
|
|
||||||
// attempt to register
|
// attempt to register
|
||||||
if err := config.Registry.Register(service, rOpts...); err != nil {
|
if err := config.Registry.Register(service, rOpts...); err != nil {
|
||||||
// set the error
|
// set the error
|
||||||
|
@ -26,6 +26,7 @@ type Options struct {
|
|||||||
Address string
|
Address string
|
||||||
Advertise string
|
Advertise string
|
||||||
Id string
|
Id string
|
||||||
|
Namespace string
|
||||||
Version string
|
Version string
|
||||||
HdlrWrappers []HandlerWrapper
|
HdlrWrappers []HandlerWrapper
|
||||||
SubWrappers []SubscriberWrapper
|
SubWrappers []SubscriberWrapper
|
||||||
@ -106,6 +107,13 @@ func Name(n string) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Namespace to register handlers in
|
||||||
|
func Namespace(n string) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Namespace = n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Unique server id
|
// Unique server id
|
||||||
func Id(id string) Option {
|
func Id(id string) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
|
@ -522,7 +522,10 @@ func (s *rpcServer) Register() error {
|
|||||||
|
|
||||||
regFunc := func(service *registry.Service) error {
|
regFunc := func(service *registry.Service) error {
|
||||||
// create registry options
|
// create registry options
|
||||||
rOpts := []registry.RegisterOption{registry.RegisterTTL(config.RegisterTTL)}
|
rOpts := []registry.RegisterOption{
|
||||||
|
registry.RegisterTTL(config.RegisterTTL),
|
||||||
|
registry.RegisterDomain(s.opts.Namespace),
|
||||||
|
}
|
||||||
|
|
||||||
var regErr error
|
var regErr error
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user