Exemple #1
0
func main() {
	config := config.New()
	apiConfig, err := config.Registry.Config()
	if err != nil {
		log.Fatal(err.Error())
	}

	kv, err := consul.NewKV(apiConfig)
	if err != nil {
		log.Fatal(err.Error())
	}

	consul := consul.NewConsul(kv, config.Registry.Prefix)

	// set up initial sync
	remote, err := config.Marathon.NewMarathon()
	if err != nil {
		log.Fatal(err.Error())
	}
	sync := marathon.NewMarathonSync(remote, consul)
	go sync.Sync()

	// set up routes
	http.HandleFunc("/health", HealthHandler)
	forwarderHandler := &ForwardHandler{consul}
	http.HandleFunc("/events", forwarderHandler.Handle)

	log.WithField("port", config.Web.Listen).Info("listening")
	log.Fatal(http.ListenAndServe(config.Web.Listen, nil))
}
Exemple #2
0
func main() {
	config := config.New()
	apiConfig, err := config.Registry.Config()
	if err != nil {
		log.Fatal(err.Error())
	}

	kv, err := consul.NewKV(apiConfig)
	if err != nil {
		log.Fatal(err.Error())
	}

	consul := consul.NewConsul(kv, config.Registry.Prefix)

	// set up initial sync
	remote, err := config.Marathon.NewMarathon()
	if err != nil {
		log.Fatal(err.Error())
	}
	sync := marathon.NewMarathonSync(remote, consul)
	go sync.Sync()

	fh := &ForwardHandler{consul}

	v, err := remote.Version()
	if err != nil {
		log.WithError(err).Warn("version parsing failed, assuming >= 0.9.0")
		v, _ = version.NewVersion("0.9.0")
	}
	minVersion, _ := version.NewConstraint(">= 0.9.0")

	if minVersion.Check(v) {
		log.WithField("version", v).Info("detected Marathon events endpoint")
		SubscribeToEventStream(config, remote, fh)
	} else {
		log.WithField("version", v).Info("detected old Marathon version -- make sure to set up an eventSubscription for this process")
		ServeWebhookReceiver(config, fh)
	}
}