basic code setup

This commit is contained in:
2023-03-28 14:27:59 +11:00
parent 266d60efa6
commit 8dc02a98bd
7 changed files with 386 additions and 0 deletions

29
utils/utils.go Normal file
View File

@@ -0,0 +1,29 @@
package utils
import (
"fmt"
"log"
"os"
"path/filepath"
)
func GetFilePath(path string) string {
// Check for empty filename
if len(path) == 0 {
return ""
}
// check if filename exists
if _, err := os.Stat(path); os.IsNotExist((err)) {
fmt.Printf("File '%s' not found, searching in same directory as binary\n", path)
// if not, check that it exists in the same directory as the currently executing binary
ex, err2 := os.Executable()
if err2 != nil {
log.Printf("Error determining binary path : '%s'", err)
return ""
}
binaryPath := filepath.Dir(ex)
path = filepath.Join(binaryPath, path)
}
return path
}