From d2dc3b4cb627663f0beab7b3059ca3955dd89671 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Tue, 17 Dec 2013 16:46:51 -0600 Subject: [PATCH] Add id to service struct --- core/service.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/core/service.go b/core/service.go index f78e324cf..79e8d7b6a 100644 --- a/core/service.go +++ b/core/service.go @@ -1,17 +1,21 @@ package core import ( - "github.com/coreos/go-etcd/etcd" "log" "os" "os/signal" + "pilosa/config" "pilosa/db" "pilosa/interfaces" "syscall" + "github.com/nu7hatch/gouuid" + + "github.com/coreos/go-etcd/etcd" ) type Service struct { Stopper + Id *uuid.UUID Etcd *etcd.Client Cluster *db.Cluster TopologyMapper *TopologyMapper @@ -23,6 +27,7 @@ type Service struct { func NewService() *Service { service := new(Service) + service.init_id() service.Etcd = etcd.NewClient(nil) service.Cluster = db.NewCluster() service.TopologyMapper = &TopologyMapper{service, "/pilosa/0"} @@ -30,6 +35,25 @@ func NewService() *Service { return service } +func (service *Service) init_id() { + var id *uuid.UUID + var err error + id_string := config.GetString("id") + if id_string == "" { + log.Println("Service id not configured, generating...") + id, err = uuid.NewV4() + if err != nil { + log.Fatal("problem generating uuid") + } + } else { + id, err = uuid.ParseHex(id_string) + if err != nil { + log.Fatalf("Service id '%s' not valid", id_string) + } + } + service.Id = id +} + func (service *Service) GetSignals() (chan os.Signal, chan os.Signal) { hupChan := make(chan os.Signal, 1) termChan := make(chan os.Signal, 1)