Esempio n. 1
0
func (s *Server) auth(fn http.HandlerFunc) http.HandlerFunc {
	if s.Credentials == "" {
		return fn
	}

	auth, err := authenticater.NewBasicAuthFromString(s.Credentials)
	if err != nil {
		log.Fatalf("server.middleware error=%v", err)
		return nil
	}
	return authenticater.WrapAuth(auth, fn)
}
Esempio n. 2
0
func main() {
	rollrus.SetupLogging(os.Getenv("ROLLBAR_TOKEN"), os.Getenv("ENVIRONMENT"))

	config, err := NewIssConfig()
	if err != nil {
		log.Fatalln(err)
	}

	log.AddHook(&DefaultFieldsHook{log.Fields{"app": "log-iss", "source": config.Deploy}})

	auth, err := authenticater.NewBasicAuthFromString(config.Tokens)
	if err != nil {
		log.Fatalln(err)
	}

	forwarderSet := newForwarderSet(config)

	shutdownCh := make(shutdownCh)
	httpServer := newHTTPServer(config, auth, fix, forwarderSet)

	go awaitShutdownSignals(httpServer.shutdownCh, shutdownCh)

	go forwarderSet.Run()

	go func() {
		if err := httpServer.Run(); err != nil {
			log.Fatalln("Unable to start HTTP server:", err)
		}
	}()

	if config.LibratoOwner != "" && config.LibratoToken != "" {
		log.WithField("source", config.LibratoSource).Info("starting librato metrics reporting")
		go librato.Librato(
			config.MetricsRegistry,
			20*time.Second,
			config.LibratoOwner,
			config.LibratoToken,
			config.LibratoSource,
			[]float64{0.50, 0.95, 0.99},
			time.Millisecond,
		)
	}

	log.WithField("at", "start").Info()
	<-shutdownCh
	log.WithField("at", "drain").Info()
	httpServer.Wait()
	log.WithField("at", "exit").Info()
}