github.com/coreservice-io/utils@v0.3.0/path_util/exe.go (about)

     1  package path_util
     2  
     3  import (
     4  	"os"
     5  	"os/exec"
     6  	"path/filepath"
     7  	"strings"
     8  )
     9  
    10  var exePath string
    11  
    12  func ExE_PathStr() string {
    13  	return exePath
    14  }
    15  
    16  //return absolute path given relative path to the executable file folder
    17  func ExE_Path(relpath string) string {
    18  	return filepath.Join(exePath, relpath)
    19  }
    20  
    21  func init() {
    22  	file, err := exec.LookPath(os.Args[0])
    23  	if err != nil {
    24  		panic(err.Error())
    25  	}
    26  	runPath, err := filepath.Abs(file)
    27  	if err != nil {
    28  		panic(err.Error())
    29  	}
    30  	index := strings.LastIndex(runPath, string(os.PathSeparator))
    31  	exePath = runPath[:index]
    32  }