コード例 #1
0
func (z *ZkConfigPersister) waitForEvents(watch *ZkWatch) {
	defer z.wg.Done()

	for {
		select {
		case event := <-watch.channel:
			if event.Err != nil {
				logging.Print("Received error from zookeeper", event)
			}
		case <-watch.stopper:
			return
		}

		channel, err := watch.listener()

		if err != nil {
			logging.Printf("Received error from zookeeper executing listener: %+v", err)
			continue
		}

		watch.channel = channel
	}
}
コード例 #2
0
ファイル: admin.go プロジェクト: maniksurtani/quotaservice
// ServeAdminConsole serves up an admin console for an Administrable using Go's built-in HTTP server
// library. `assetsDirectory` contains HTML templates and other UI assets. If empty, no UI will be
// served, and only REST endpoints under `/api/` will be served.
func ServeAdminConsole(a Administrable, mux *http.ServeMux, assetsDirectory string, development bool) {
	if assetsDirectory != "" {
		msg := "Serving assets from %s"

		if development {
			msg += " (in development mode)"
		}

		logging.Printf(msg, assetsDirectory)

		mux.Handle("/", loggingHandler(http.RedirectHandler("/admin/", 301)))
		mux.Handle("/admin/", loggingHandler(NewUIHandler(a, assetsDirectory, development)))
		mux.Handle("/js/", loggingHandler(http.FileServer(http.Dir(assetsDirectory))))
		mux.Handle("/favicon.ico", http.NotFoundHandler())
	} else {
		logging.Print("Not serving admin web UI.")
		mux.Handle("/", loggingHandler(http.NotFoundHandler()))
	}

	bucketsHandler := NewBucketsAPIHandler(a)
	namespacesHandler := NewNamespacesAPIHandler(a)

	apiHandler := loggingHandler(jsonResponseHandler(apiRequestHandler(
		namespacesHandler, bucketsHandler)))

	mux.Handle("/api", apiHandler)
	mux.Handle("/api/", apiHandler)

	statsHandler := loggingHandler(jsonResponseHandler(NewStatsAPIHandler(a)))
	mux.Handle("/api/stats", statsHandler)
	mux.Handle("/api/stats/", statsHandler)

	configsHandler := loggingHandler(jsonResponseHandler(NewConfigsAPIHandler(a)))
	mux.Handle("/api/configs", configsHandler)
	mux.Handle("/api/configs/", configsHandler)
}