diff --git a/init.go b/init.go index 8bf86d8..7f78400 100644 --- a/init.go +++ b/init.go @@ -30,6 +30,8 @@ var ( Map *ownMap // Calculate ... Calculate *calculate + // Project ... + Project = &project{} ) func init() { diff --git a/project.go b/project.go new file mode 100644 index 0000000..cd17347 --- /dev/null +++ b/project.go @@ -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 +} diff --git a/project_test.go b/project_test.go new file mode 100644 index 0000000..37d984a --- /dev/null +++ b/project_test.go @@ -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()) +}