fea: update project
This commit is contained in:
2
go.mod
2
go.mod
@@ -4,7 +4,7 @@ go 1.21
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/mitchellh/go-homedir v1.1.0
|
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
|
github.com/spaolacci/murmur3 v1.1.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -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/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 h1:BtR3DsxpApHfKReaPO1fCqF4pThRwH9uwvXzm+GnMFQ=
|
||||||
github.com/mozillazg/go-pinyin v0.20.0/go.mod h1:iR4EnMMRXkfpFVV5FMi4FNB6wGq9NV6uDWbUuPhP4Yc=
|
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 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
|
||||||
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
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=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
|||||||
48
project.go
48
project.go
@@ -20,10 +20,6 @@ type project struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetExecutablePath 获取可执行文件的路径
|
// GetExecutablePath 获取可执行文件的路径
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 12:41 2022/10/14
|
|
||||||
func (p *project) GetExecutablePath() (string, error) {
|
func (p *project) GetExecutablePath() (string, error) {
|
||||||
dir, err := filepath.Abs(filepath.Dir(os.Args[0])) //返回绝对路径 filepath.Dir(os.Args[0])去除最后一个元素的路径
|
dir, err := filepath.Abs(filepath.Dir(os.Args[0])) //返回绝对路径 filepath.Dir(os.Args[0])去除最后一个元素的路径
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -33,19 +29,11 @@ func (p *project) GetExecutablePath() (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetFileSystemSeparator 获取当前文件系统的路径分隔符
|
// GetFileSystemSeparator 获取当前文件系统的路径分隔符
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 12:51 2022/10/14
|
|
||||||
func (p *project) GetFileSystemSeparator() string {
|
func (p *project) GetFileSystemSeparator() string {
|
||||||
return string(filepath.Separator)
|
return string(filepath.Separator)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuildPath 构建路径
|
// BuildPath 构建路径
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 12:57 2022/10/14
|
|
||||||
func (p *project) BuildPath(filePathList ...string) string {
|
func (p *project) BuildPath(filePathList ...string) string {
|
||||||
projectRootPath, _ := p.GetExecutablePath()
|
projectRootPath, _ := p.GetExecutablePath()
|
||||||
if len(filePathList) == 0 {
|
if len(filePathList) == 0 {
|
||||||
@@ -53,49 +41,29 @@ func (p *project) BuildPath(filePathList ...string) string {
|
|||||||
return projectRootPath
|
return projectRootPath
|
||||||
}
|
}
|
||||||
// 第一个特殊处理
|
// 第一个特殊处理
|
||||||
if filePathList[0] == "." || len(filePathList[0]) == 0 {
|
|
||||||
filePathList[0] = projectRootPath
|
|
||||||
} else {
|
|
||||||
if strings.ToLower(runtime.GOOS) == "windows" {
|
if strings.ToLower(runtime.GOOS) == "windows" {
|
||||||
// windows
|
// windows
|
||||||
if strings.HasPrefix(filePathList[0], "."+p.GetFileSystemSeparator()) {
|
if !strings.Contains(filePathList[0], ":") {
|
||||||
// 相对路径
|
|
||||||
filePathList[0] = strings.ReplaceAll(filePathList[0], ".", projectRootPath)
|
|
||||||
} else if !strings.Contains(filePathList[0], ":") {
|
|
||||||
// 不包含 :, 是 相对路径,拼成绝对路径
|
// 不包含 :, 是 相对路径,拼成绝对路径
|
||||||
filePathList[0] = projectRootPath + p.GetFileSystemSeparator() + strings.TrimLeft(filePathList[0], p.GetFileSystemSeparator())
|
filePathList[0] = filepath.Join(projectRootPath, filePathList[0])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// unix/ linux
|
// unix/ linux
|
||||||
if strings.HasPrefix(filePathList[0], "."+p.GetFileSystemSeparator()) {
|
if !strings.HasPrefix(filePathList[0], p.GetFileSystemSeparator()) {
|
||||||
filePathList[0] = strings.ReplaceAll(filePathList[0], ".", projectRootPath)
|
// 不是绝对路径
|
||||||
} else if !strings.HasPrefix(filePathList[0], p.GetFileSystemSeparator()) {
|
filePathList[0] = filepath.Join(projectRootPath, filePathList[0])
|
||||||
filePathList[0] = projectRootPath + p.GetFileSystemSeparator() + filePathList[0]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return filepath.Join(filePathList...)
|
||||||
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())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetProjectPath 获取项目目录
|
// GetWorkDir 获取工作目录
|
||||||
//
|
func (p *project) GetWorkDir() string {
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 14:39 2023/1/13
|
|
||||||
func (p *project) GetProjectPath() string {
|
|
||||||
dir, _ := os.Getwd()
|
dir, _ := os.Getwd()
|
||||||
return dir
|
return dir
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetHomeDir 获取家目录
|
// GetHomeDir 获取家目录
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 22:31 2023/4/18
|
|
||||||
func (p *project) GetHomeDir() string {
|
func (p *project) GetHomeDir() string {
|
||||||
homePath, _ := homedir.Dir()
|
homePath, _ := homedir.Dir()
|
||||||
return homePath
|
return homePath
|
||||||
|
|||||||
Reference in New Issue
Block a user