From f5086c77e0dbaec938cb5707ba8ded2fea5af91d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Fri, 14 Oct 2022 12:50:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96=E5=8F=AF?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E6=96=87=E4=BB=B6=E7=BB=9D=E5=AF=B9=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- init.go | 2 ++ project.go | 30 ++++++++++++++++++++++++++++++ project_test.go | 17 +++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 project.go create mode 100644 project_test.go 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()) +}