fea: update project

This commit is contained in:
2026-01-03 21:34:13 +08:00
parent 6ee2c90464
commit c28a0ffa8e
3 changed files with 16 additions and 46 deletions

2
go.mod
View File

@@ -4,7 +4,7 @@ go 1.21
require (
github.com/mitchellh/go-homedir v1.1.0
github.com/mozillazg/go-pinyin v0.20.0
github.com/mozillazg/go-pinyin v0.21.0
github.com/spaolacci/murmur3 v1.1.0
)

2
go.sum
View File

@@ -16,6 +16,8 @@ github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mozillazg/go-pinyin v0.20.0 h1:BtR3DsxpApHfKReaPO1fCqF4pThRwH9uwvXzm+GnMFQ=
github.com/mozillazg/go-pinyin v0.20.0/go.mod h1:iR4EnMMRXkfpFVV5FMi4FNB6wGq9NV6uDWbUuPhP4Yc=
github.com/mozillazg/go-pinyin v0.21.0 h1:Wo8/NT45z7P3er/9YSLHA3/kjZzbLz5hR7i+jGeIGao=
github.com/mozillazg/go-pinyin v0.21.0/go.mod h1:iR4EnMMRXkfpFVV5FMi4FNB6wGq9NV6uDWbUuPhP4Yc=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

View File

@@ -20,10 +20,6 @@ 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 {
@@ -33,19 +29,11 @@ func (p *project) GetExecutablePath() (string, error) {
}
// GetFileSystemSeparator 获取当前文件系统的路径分隔符
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:51 2022/10/14
func (p *project) GetFileSystemSeparator() string {
return string(filepath.Separator)
}
// BuildPath 构建路径
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:57 2022/10/14
func (p *project) BuildPath(filePathList ...string) string {
projectRootPath, _ := p.GetExecutablePath()
if len(filePathList) == 0 {
@@ -53,49 +41,29 @@ func (p *project) BuildPath(filePathList ...string) string {
return projectRootPath
}
// 第一个特殊处理
if filePathList[0] == "." || len(filePathList[0]) == 0 {
filePathList[0] = projectRootPath
if strings.ToLower(runtime.GOOS) == "windows" {
// windows
if !strings.Contains(filePathList[0], ":") {
// 不包含 :, 是 相对路径,拼成绝对路径
filePathList[0] = filepath.Join(projectRootPath, filePathList[0])
}
} else {
if strings.ToLower(runtime.GOOS) == "windows" {
// windows
if strings.HasPrefix(filePathList[0], "."+p.GetFileSystemSeparator()) {
// 相对路径
filePathList[0] = strings.ReplaceAll(filePathList[0], ".", projectRootPath)
} else if !strings.Contains(filePathList[0], ":") {
// 不包含 :, 是 相对路径,拼成绝对路径
filePathList[0] = projectRootPath + p.GetFileSystemSeparator() + strings.TrimLeft(filePathList[0], p.GetFileSystemSeparator())
}
} else {
// unix/ linux
if strings.HasPrefix(filePathList[0], "."+p.GetFileSystemSeparator()) {
filePathList[0] = strings.ReplaceAll(filePathList[0], ".", projectRootPath)
} else if !strings.HasPrefix(filePathList[0], p.GetFileSystemSeparator()) {
filePathList[0] = projectRootPath + p.GetFileSystemSeparator() + filePathList[0]
}
// unix/ linux
if !strings.HasPrefix(filePathList[0], p.GetFileSystemSeparator()) {
// 不是绝对路径
filePathList[0] = filepath.Join(projectRootPath, filePathList[0])
}
}
filePathList[0] = strings.TrimRight(filePathList[0], p.GetFileSystemSeparator())
for idx := 1; idx < len(filePathList); idx++ {
filePathList[idx] = strings.Trim(filePathList[idx], p.GetFileSystemSeparator())
}
return strings.Join(filePathList, p.GetFileSystemSeparator())
return filepath.Join(filePathList...)
}
// GetProjectPath 获取项目目录
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:39 2023/1/13
func (p *project) GetProjectPath() string {
// GetWorkDir 获取工作目录
func (p *project) GetWorkDir() string {
dir, _ := os.Getwd()
return dir
}
// GetHomeDir 获取家目录
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 22:31 2023/4/18
func (p *project) GetHomeDir() string {
homePath, _ := homedir.Dir()
return homePath