From bd54fa707a03125878a23f1ad4c93f25708cf4d3 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 13 Jan 2025 08:55:48 -0600 Subject: code to determine the go src directory --- goWork.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 goWork.go (limited to 'goWork.go') diff --git a/goWork.go b/goWork.go new file mode 100644 index 0000000..7dbfac9 --- /dev/null +++ b/goWork.go @@ -0,0 +1,34 @@ +package fhelp + +import ( + "os" + + "go.wit.com/log" +) + +/* +try to determine the GO working dir +this will look for a go.work file, otherwise +it will default to ~/go/src + +returns: +string # ~/go/src or the path to the go.work file +bool # true if the user is using a go.work file +err # if everything goes wrong, the error +*/ +func DetermineGoPath() (string, bool, error) { + gosrc := os.Getenv("FORGE_GOSRC") + if gosrc != "" { + hasWork := goWorkExists(gosrc) + log.Info("Using ENV{FORGE_GOSRC} =", gosrc) + return gosrc, hasWork, nil + } + + gosrc, err := findGoSrc() + if err != nil { + log.Info("fhelp.DetermineGoPath()", err) + } + hasWork := goWorkExists(gosrc) + + return gosrc, hasWork, err +} -- cgit v1.2.3