Exemple #1
0
func main() {
	cfg, err := config.ParseEnv()
	if err != nil {
		log.Fatal(err)
	}
	uaa := &cflib.UAA{
		URL:          cfg.UaaURL,
		Username:     cfg.Username,
		Password:     cfg.Password,
		ClientID:     cfg.ClientID,
		ClientSecret: cfg.ClientSecret,
	}
	cc := &cflib.CC{
		URL: cfg.ApiURL,
	}
	logcounter := logcounter.New(uaa, cc, cfg)

	go func() {
		if err := logcounter.Start(); err != nil {
			log.Fatal(err)
		}
	}()

	consumer := consumer.New(cfg.DopplerURL, &tls.Config{InsecureSkipVerify: true}, nil)

	fmt.Println("===== Streaming Firehose (will only succeed if you have admin credentials)")

	// notify on ctrl+c
	terminate := make(chan os.Signal, 1)
	signal.Notify(terminate, os.Interrupt)
	go func() {
		for range terminate {
			logcounter.Stop()
		}
	}()

	for {
		authToken, err := uaa.GetAuthToken()
		if err != nil || authToken == "" {
			fmt.Fprintf(os.Stderr, "error getting token %s\n", err)
			continue
		}
		fmt.Println("got new oauth token")
		msgs, errors := consumer.FirehoseWithoutReconnect(cfg.SubscriptionID, authToken)

		go logcounter.HandleMessages(msgs)
		done := logcounter.HandleErrors(errors, terminate, consumer)
		if done {
			return
		}
	}
}
					defer mu.Unlock()
					if request == nil {
						return ""
					}
					return request.URL.Path
				}).Should(Equal("/report"))
				testServer.Close()
			}()

			port := testPort()

			cc := newMockCC()
			uaa := newMockUAA()
			cfg := conf(port, testServer)

			lc := logcounter.New(uaa, cc, cfg)
			go func() {
				defer GinkgoRecover()
				err := lc.Start()
				Expect(err).ToNot(HaveOccurred())
			}()
			defer lc.Stop()

			Eventually(func() bool { return checkEndpoint(port, "?report", http.StatusOK) }).Should(BeTrue())
		})

		It("returns 404 status for unknown routes", func() {
			var (
				mu       sync.Mutex
				request  *http.Request
				statuses = make(chan int, 2)