增加获取可执行文件绝对路径的方法
This commit is contained in:
parent
1c9c8be53c
commit
f5086c77e0
2
init.go
2
init.go
@ -30,6 +30,8 @@ var (
|
||||
Map *ownMap
|
||||
// Calculate ...
|
||||
Calculate *calculate
|
||||
// Project ...
|
||||
Project = &project{}
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
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
|
||||
}
|
17
project_test.go
Normal file
17
project_test.go
Normal 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())
|
||||
}
|
Loading…
Reference in New Issue
Block a user