diff --git a/.gitignore b/.gitignore index e26d5efa0..f5ff4aab1 100644 --- a/.gitignore +++ b/.gitignore @@ -51,4 +51,4 @@ experimental/_integration/_integration *sublime-workspace *npm-debug.log app/static.go -prog/app/static.go +prog/static.go diff --git a/Makefile b/Makefile index 1497fb15d..dfe9cf348 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ $(SCOPE_EXPORT): $(SCOPE_EXE) $(DOCKER_DISTRIB) docker/weave $(RUNSVINIT) docker $(RUNSVINIT): vendor/runsvinit/*.go -$(SCOPE_EXE): $(shell find ./ -type f -name *.go) prog/app/static.go +$(SCOPE_EXE): $(shell find ./ -type f -name *.go) prog/static.go ifeq ($(BUILD_IN_CONTAINER),true) $(SCOPE_EXE) $(RUNSVINIT): $(SCOPE_BACKEND_BUILD_UPTODATE) @@ -58,10 +58,10 @@ $(RUNSVINIT): go build -ldflags "-extldflags \"-static\"" -o $@ ./$(@D) endif -static: prog/app/static.go +static: prog/static.go -prog/app/static.go: client/build/app.js - esc -o $@ -prefix client/build -pkg app client/build +prog/static.go: client/build/app.js + esc -o $@ -prefix client/build client/build ifeq ($(BUILD_IN_CONTAINER),true) client/build/app.js: $(shell find client/app/scripts -type f) $(SCOPE_UI_BUILD_UPTODATE) @@ -101,7 +101,7 @@ clean: go clean ./... $(SUDO) docker rmi $(SCOPE_UI_BUILD_IMAGE) $(SCOPE_BACKEND_BUILD_IMAGE) >/dev/null 2>&1 || true rm -rf $(SCOPE_EXPORT) $(SCOPE_UI_BUILD_UPTODATE) $(SCOPE_BACKEND_BUILD_UPTODATE) \ - $(SCOPE_EXE) $(RUNSVINIT) prog/app/static.go client/build/app.js docker/weave + $(SCOPE_EXE) $(RUNSVINIT) prog/static.go client/build/app.js docker/weave ifeq ($(BUILD_IN_CONTAINER),true) tests: $(SCOPE_BACKEND_BUILD_UPTODATE) diff --git a/prog/app/main.go b/prog/app.go similarity index 86% rename from prog/app/main.go rename to prog/app.go index 7242392ac..415932057 100644 --- a/prog/app/main.go +++ b/prog/app.go @@ -1,4 +1,4 @@ -package app +package main import ( "flag" @@ -6,13 +6,11 @@ import ( "log" "math/rand" "net/http" + _ "net/http/pprof" "strconv" "strings" "time" - // a blank import should be only in a main or test package, or have a comment justifying it - _ "net/http/pprof" - "github.com/gorilla/mux" "github.com/weaveworks/weave/common" @@ -21,7 +19,7 @@ import ( ) // Router creates the mux for all the various app components. -func Router(c app.Collector) *mux.Router { +func router(c app.Collector) *mux.Router { router := mux.NewRouter() app.RegisterTopologyRoutes(c, router) app.RegisterReportPostHandler(c, router) @@ -31,7 +29,7 @@ func Router(c app.Collector) *mux.Router { } // Main runs the app -func Main() { +func appMain() { var ( window = flag.Duration("window", 15*time.Second, "window") listen = flag.String("http.address", ":"+strconv.Itoa(xfer.AppPort), "webserver listen address") @@ -55,7 +53,7 @@ func Main() { rand.Seed(time.Now().UnixNano()) app.UniqueID = strconv.FormatInt(rand.Int63(), 16) log.Printf("app starting, version %s, ID %s", app.Version, app.UniqueID) - http.Handle("/", Router(app.NewCollector(*window))) + http.Handle("/", router(app.NewCollector(*window))) go func() { log.Printf("listening on %s", *listen) log.Print(http.ListenAndServe(*listen, nil)) diff --git a/prog/main.go b/prog/main.go index 059679474..01926360c 100644 --- a/prog/main.go +++ b/prog/main.go @@ -3,13 +3,10 @@ package main import ( "fmt" "os" - - "github.com/weaveworks/scope/prog/app" - "github.com/weaveworks/scope/prog/probe" ) func usage() { - fmt.Printf("usage: %s (app|probe) args...\n", os.Args[0]) + fmt.Fprintf(os.Stderr, "usage: %s (app|probe) args...\n", os.Args[0]) os.Exit(1) } @@ -23,9 +20,9 @@ func main() { switch module { case "app": - app.Main() + appMain() case "probe": - probe.Main() + probeMain() default: usage() } diff --git a/prog/probe/main.go b/prog/probe.go similarity index 97% rename from prog/probe/main.go rename to prog/probe.go index b684d1d25..d289e4020 100644 --- a/prog/probe/main.go +++ b/prog/probe.go @@ -1,4 +1,4 @@ -package probe +package main import ( "flag" @@ -7,14 +7,12 @@ import ( "math/rand" "net" "net/http" + _ "net/http/pprof" "os" "strconv" "strings" "time" - // a blank import should be only in a main or test package, or have a comment justifying it - _ "net/http/pprof" - "github.com/armon/go-metrics" "github.com/weaveworks/weave/common" @@ -34,7 +32,7 @@ import ( var version = "dev" // set at build time // Main runs the probe -func Main() { +func probeMain() { var ( targets = []string{fmt.Sprintf("localhost:%d", xfer.AppPort), fmt.Sprintf("scope.weave.local:%d", xfer.AppPort)} token = flag.String("token", "default-token", "probe token")