diff --git a/common/registry/stub.go b/common/registry/stub.go index 073ac67..d719c4d 100644 --- a/common/registry/stub.go +++ b/common/registry/stub.go @@ -50,7 +50,3 @@ func (s *stubReg) GetService(serviceName, version string) ([]Service, error) { func (s *stubReg) Name() string { return "stub" } - -func key(service Service) string { - return service.Name + "-" + service.Version -} diff --git a/common/service/grpc_service.go b/common/service/grpc_service.go index 69ac073..aff6ff1 100644 --- a/common/service/grpc_service.go +++ b/common/service/grpc_service.go @@ -5,11 +5,9 @@ import ( "net/http" "time" - "github.com/google/uuid" "github.com/grpc-ecosystem/go-grpc-prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/while-loop/levit/common/log" - levnet "github.com/while-loop/levit/common/net" "github.com/while-loop/levit/common/registry" "google.golang.org/grpc" ) @@ -31,19 +29,7 @@ func NewGrpcService(options Options) Service { metrics(rpc, options.MetricsAddr) } - if options.IP == "" { - options.IP = levnet.GetIP() - } - - if options.Port <= 0 { - options.Port = 8080 - } - - if options.TTL == 0 { - options.TTL = 30 * time.Second - } - - options.UUID = uuid.New().String() + options.applyDefaults() s := &grpcService{rpc, options, diff --git a/common/service/options.go b/common/service/options.go index d59bf87..fb928e6 100644 --- a/common/service/options.go +++ b/common/service/options.go @@ -3,6 +3,9 @@ package service import ( "fmt" "time" + + "github.com/google/uuid" + levnet "github.com/while-loop/levit/common/net" ) type Options struct { @@ -15,6 +18,21 @@ type Options struct { TTL time.Duration } +func (o *Options) applyDefaults() { + if o.IP == "" { + o.IP = levnet.GetIP() + } + + if o.Port <= 0 { + o.Port = 8080 + } + + if o.TTL == 0 { + o.TTL = 30 * time.Second + } + + o.UUID = uuid.New().String() +} func (o Options) laddr() string { return fmt.Sprintf("%s:%d", o.IP, o.Port) } diff --git a/users/cmd/usersd/main.go b/users/cmd/usersd/main.go index 6d68791..65058b4 100644 --- a/users/cmd/usersd/main.go +++ b/users/cmd/usersd/main.go @@ -4,7 +4,6 @@ import ( "flag" "strconv" "strings" - "time" "github.com/while-loop/levit/common/log" "github.com/while-loop/levit/common/registry" @@ -41,7 +40,6 @@ func main() { ServiceName: version.Name, ServiceVersion: version.Version, MetricsAddr: ":8181", - TTL: 5 * time.Second, IP: parts[0], Port: int(port), })