From 3eea39302e5de362def3012dcc8dc0204ad020e7 Mon Sep 17 00:00:00 2001 From: Marius Orcsik Date: Tue, 6 Aug 2024 17:40:27 +0200 Subject: [PATCH] Create a variable for the application name Change how we enable the perf subsystem --- cmd/motley/main.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/cmd/motley/main.go b/cmd/motley/main.go index c1ba759..d0b5e06 100644 --- a/cmd/motley/main.go +++ b/cmd/motley/main.go @@ -10,7 +10,6 @@ import ( "os" "path/filepath" "runtime/debug" - "strconv" "strings" "time" @@ -38,25 +37,24 @@ func openlog(name string) io.Writer { return f } -func perfEnabled() bool { - val, err := strconv.ParseBool(os.Getenv("MOTLEY_ENABLE_PERF")) - if err != nil { - return false - } - return val +func perfEnabled() (string, bool) { + l := os.Getenv("MOTLEY_PERF_LISTEN") + return l, len(l) > 0 } +var AppName = "motley" + func main() { if build, ok := debug.ReadBuildInfo(); ok && version == "HEAD" && build.Main.Version != "(devel)" { version = build.Main.Version } - l := lw.Dev(lw.SetOutput(openlog("motley")), lw.SetLevel(lw.TraceLevel)) + l := lw.Dev(lw.SetOutput(openlog(AppName)), lw.SetLevel(lw.TraceLevel)) ktx := kong.Parse( &Motley, kong.Bind(l), - kong.Name("motley"), + kong.Name(AppName), kong.Description("Helper utility to manage a FedBOX instance"), kong.Vars{ "envs": strings.Join([]string{string(env.DEV), string(env.QA), string(env.PROD)}, ", "), @@ -65,10 +63,10 @@ func main() { }, ) - if perfEnabled() { + if listenOn, enabled := perfEnabled(); enabled { // Server for pprof go func() { - fmt.Println(http.ListenAndServe("localhost:6060", nil)) + fmt.Println(http.ListenAndServe(listenOn, nil)) }() } -- 2.45.2