Skip to content

Commit

Permalink
Set register ttl and interval by default
Browse files Browse the repository at this point in the history
  • Loading branch information
asim committed Sep 23, 2019
1 parent d8dc713 commit fa0d020
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
6 changes: 4 additions & 2 deletions config/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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))
}

Expand Down
6 changes: 4 additions & 2 deletions server/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 9 additions & 7 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fa0d020

Please sign in to comment.