增加获取可执行文件绝对路径的方法
This commit is contained in:
30
project.go
Normal file
30
project.go
Normal file
@@ -0,0 +1,30 @@
|
||||
// Package util ...
|
||||
//
|
||||
// Description : util ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2022-10-14 12:39
|
||||
package util
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type project struct {
|
||||
|
||||
}
|
||||
|
||||
// GetExecutablePath 获取可执行文件的路径
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 12:41 2022/10/14
|
||||
func (p *project) GetExecutablePath() (string, error) {
|
||||
dir, err := filepath.Abs(filepath.Dir(os.Args[0])) //返回绝对路径 filepath.Dir(os.Args[0])去除最后一个元素的路径
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return dir, nil
|
||||
}
|
||||
Reference in New Issue
Block a user