-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simpler functions not relying on paths to init.
- Loading branch information
1 parent
5da2add
commit c6990e6
Showing
6 changed files
with
113 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package path | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
//GetBinaryPath will return the location of the binary or the project in go run mode. | ||
func GetBinaryPath() (path string) { | ||
ex, err := os.Executable() | ||
if err != nil { | ||
log.Println("path.GetBinaryPath() failed to get Executable: " + err.Error()) | ||
return | ||
} | ||
exPath := filepath.Dir(ex) | ||
if strings.Contains(exPath, "go-build") { //This means we are running in go run and need to use the goPath | ||
if len(os.Args) >= 2 { | ||
path = os.Args[1] + PathSeparator | ||
} else { | ||
log.Println("Using GoCore in go run, you must pass go run yourMain.go $(pwd) so it can get your path of your project") | ||
os.Exit(1) | ||
} | ||
} else { | ||
if strings.Index(exPath, "Contents/MacOS") != -1 { | ||
dirs := strings.Split(exPath, "/") | ||
dirs = dirs[:len(dirs)-3] | ||
path = strings.Join(dirs, "/") + PathSeparator | ||
} else { | ||
path = exPath + PathSeparator | ||
} | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package path | ||
|
||
//PathSeparator provides windows or non-windows path separator. | ||
const PathSeparator = "/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package path | ||
|
||
const PathSeparator = "\\" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters