From 822c09370e11faa57e9a6264ac54b2df7a52c682 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Mon, 14 Sep 2015 16:01:28 +0200 Subject: [PATCH] app: show unique ID in /api --- app/main.go | 13 +++++++++---- app/router.go | 3 ++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/main.go b/app/main.go index 7e8e3c3b3..0320fc2cf 100644 --- a/app/main.go +++ b/app/main.go @@ -16,8 +16,13 @@ import ( "github.com/weaveworks/scope/xfer" ) -// Set during buildtime. -var version = "dev" +var ( + // Set at buildtime. + version = "dev" + + // Set at runtime. + uniqueID = "0" +) func main() { var ( @@ -33,8 +38,8 @@ func main() { } rand.Seed(time.Now().UnixNano()) - id := strconv.FormatInt(rand.Int63(), 16) - log.Printf("app starting, version %s, ID %s", version, id) + uniqueID = strconv.FormatInt(rand.Int63(), 16) + log.Printf("app starting, version %s, ID %s", version, uniqueID) c := xfer.NewCollector(*window) http.Handle("/", Router(c)) diff --git a/app/router.go b/app/router.go index a1c866173..9e99c3ed3 100644 --- a/app/router.go +++ b/app/router.go @@ -121,11 +121,12 @@ func captureTopology(rep xfer.Reporter, f func(xfer.Reporter, topologyView, http // APIDetails are some generic details that can be fetched from /api type APIDetails struct { + ID string `json:"id"` Version string `json:"version"` } func apiHandler(w http.ResponseWriter, r *http.Request) { - respondWith(w, http.StatusOK, APIDetails{Version: version}) + respondWith(w, http.StatusOK, APIDetails{ID: uniqueID, Version: version}) } // Topology option labels should tell the current state. The first item must