增加获取可执行文件绝对路径的方法

This commit is contained in:
zhangdeman committed 2022-10-14 12:50:03 +08:00
1 parent 1c9c8be53c
commit f5086c77e0
3 files changed
+49

No files matched your search

+2
View File
@@ -30,6 +30,8 @@ var (
Map *ownMap
// Calculate ...
Calculate *calculate
// Project ...
Project = &project{}
)
func init() {
+30
View 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
}
+17
View File
@@ -0,0 +1,17 @@
// Package util ...
//
// Description : util ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2022-10-14 12:47
package util
import (
"fmt"
"testing"
)
func Test_project_GetExecutablePath(t *testing.T) {
fmt.Println(Project.GetExecutablePath())
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.