From 3061e3d0c55aece83e013feca6ec0e9cdfde55bb Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 4 Oct 2021 17:04:49 +0200 Subject: [PATCH] Introduce function utils.AppName() --- pkg/utils/utils.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 18606ea0..6c8b4fff 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -9,6 +9,8 @@ import ( "github.com/pkg/errors" "golang.org/x/exp/utf8string" "math" + "os" + "path/filepath" "strings" "time" "unicode" @@ -179,3 +181,13 @@ func ConvertCamelCase(s string, _case int, sep byte) string { return b.String() } + +// AppName returns the name of the executable that started this program (process). +func AppName() string { + exe, err := os.Executable() + if err != nil { + exe = os.Args[0] + } + + return filepath.Base(exe) +}