ma-api/ModulePath/ModulePath.go

40 lines
662 B
Go

package ModulePath
import (
// "errors"
// "fmt"
"os"
// "os/exec"
"path/filepath"
// "strings"
)
func GetModuleCurrentPath() (string, error) {
file, err := os.Executable()
if err != nil {
return "", err
}
exPath := filepath.Dir(file)
return exPath, nil
/*file, err := exec.LookPath(os.Args[0])
if err != nil {
fmt.Println("lookpath err:", err.Error())
return "", err
}
path, err := filepath.Abs(file)
if err != nil {
return "", err
}
i := strings.LastIndex(path, "/")
if i < 0 {
i = strings.LastIndex(path, "\\")
}
if i < 0 {
return "", errors.New(`error: Can't find "/" or "\".`)
}
return string(path[0 : i+1]), nil*/
}