diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index beb4ba97..512ed83d 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -95,11 +95,13 @@ var ( cli.IntFlag{ Name: "register_ttl", EnvVar: "MICRO_REGISTER_TTL", + Value: 60, Usage: "Register TTL in seconds", }, cli.IntFlag{ Name: "register_interval", EnvVar: "MICRO_REGISTER_INTERVAL", + Value: 30, Usage: "Register interval in seconds", }, cli.StringFlag{ @@ -417,11 +419,11 @@ func (c *cmd) Before(ctx *cli.Context) error { serverOpts = append(serverOpts, server.Advertise(ctx.String("server_advertise"))) } - if ttl := time.Duration(ctx.GlobalInt("register_ttl")); ttl > 0 { + if ttl := time.Duration(ctx.GlobalInt("register_ttl")); ttl >= 0 { serverOpts = append(serverOpts, server.RegisterTTL(ttl*time.Second)) } - if val := time.Duration(ctx.GlobalInt("register_interval")); val > 0 { + if val := time.Duration(ctx.GlobalInt("register_interval")); val >= 0 { serverOpts = append(serverOpts, server.RegisterInterval(val*time.Second)) } diff --git a/server/options.go b/server/options.go index c75ed4d1..110699ae 100644 --- a/server/options.go +++ b/server/options.go @@ -42,8 +42,10 @@ type Options struct { func newOptions(opt ...Option) Options { opts := Options{ - Codecs: make(map[string]codec.NewCodec), - Metadata: map[string]string{}, + Codecs: make(map[string]codec.NewCodec), + Metadata: map[string]string{}, + RegisterInterval: DefaultRegisterInterval, + RegisterTTL: DefaultRegisterTTL, } for _, o := range opt { diff --git a/server/server.go b/server/server.go index 5c8d5e4e..98f2cddb 100644 --- a/server/server.go +++ b/server/server.go @@ -116,13 +116,15 @@ type Subscriber interface { type Option func(*Options) var ( - DefaultAddress = ":0" - DefaultName = "go.micro.server" - DefaultVersion = time.Now().Format("2006.01.02.15.04") - DefaultId = uuid.New().String() - DefaultServer Server = newRpcServer() - DefaultRouter = newRpcRouter() - DefaultRegisterCheck = func(context.Context) error { return nil } + DefaultAddress = ":0" + DefaultName = "go.micro.server" + DefaultVersion = time.Now().Format("2006.01.02.15.04") + DefaultId = uuid.New().String() + DefaultServer Server = newRpcServer() + DefaultRouter = newRpcRouter() + DefaultRegisterCheck = func(context.Context) error { return nil } + DefaultRegisterInterval = time.Second * 30 + DefaultRegisterTTL = time.Minute ) // DefaultOptions returns config options for the default service