func (c *VcapComponent) Start() error { if c.Varz.Type == "" { err := errors.New("type is required") log.Error("Component type is required", err) return err } c.quitCh = make(chan struct{}, 1) c.Varz.StartTime = schema.Time(time.Now()) guid, err := uuid.GenerateUUID() if err != nil { return err } c.Varz.UUID = fmt.Sprintf("%d-%s", c.Varz.Index, guid) if c.Varz.Host == "" { host, err := localip.LocalIP() if err != nil { log.Error("error-getting-localIP", err) return err } port, err := localip.LocalPort() if err != nil { log.Error("error-getting-localPort", err) return err } c.Varz.Host = fmt.Sprintf("%s:%d", host, port) } if c.Varz.Credentials == nil || len(c.Varz.Credentials) != 2 { user, err := uuid.GenerateUUID() if err != nil { return err } password, err := uuid.GenerateUUID() if err != nil { return err } c.Varz.Credentials = []string{user, password} } if c.Logger != nil { log = c.Logger } c.Varz.NumCores = runtime.NumCPU() procStat = NewProcessStatus() c.ListenAndServe() return nil }
func SetVcapRequestIdHeader(request *http.Request, logger lager.Logger) { guid, err := uuid.GenerateUUID() if err == nil { request.Header.Set(VcapRequestIdHeader, guid) if logger != nil { logger.Debug("vcap-request-id-header-set", lager.Data{VcapRequestIdHeader: guid}) } } }
func (a *TestApp) Register() { uuid, _ := uuid.GenerateUUID() rm := registerMessage{ Host: "localhost", Port: a.port, Uris: a.urls, Tags: a.tags, Dea: "dea", App: "0", StaleThresholdInSeconds: 1, RouteServiceUrl: a.routeService, PrivateInstanceId: uuid, } b, _ := json.Marshal(rm) a.mbusClient.Publish("router.register", b) }
func createSubscriber( logger lager.Logger, c *config.Config, natsClient *nats.Conn, registry rregistry.RegistryInterface, startMsgChan chan struct{}, ) ifrit.Runner { guid, err := uuid.GenerateUUID() if err != nil { logger.Fatal("failed-to-generate-uuid", err) } opts := &mbus.SubscriberOpts{ ID: fmt.Sprintf("%d-%s", c.Index, guid), MinimumRegisterIntervalInSeconds: int(c.StartResponseDelayInterval.Seconds()), PruneThresholdInSeconds: int(c.DropletStaleThreshold.Seconds()), } return mbus.NewSubscriber(logger.Session("subscriber"), natsClient, registry, startMsgChan, opts) }
package uuid_test import ( "code.cloudfoundry.org/gorouter/common/uuid" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("UUID", func() { It("creates a uuid", func() { uuid, err := uuid.GenerateUUID() Expect(err).ToNot(HaveOccurred()) Expect(uuid).To(HaveLen(36)) }) })