1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-08 22:52:29 +08:00

feat: add CurrentPath

This commit is contained in:
dudaodong
2023-04-05 15:55:55 +08:00
parent 3685aee02b
commit 6e7300bbbf
4 changed files with 72 additions and 0 deletions

View File

@@ -15,6 +15,7 @@ import (
"os"
"path"
"path/filepath"
"runtime"
"strings"
)
@@ -345,3 +346,15 @@ func MiMeType(file any) string {
}
return mediatype
}
// CurrentPath return current absolute path.
// Play: todo
func CurrentPath() string {
var absPath string
_, filename, _, ok := runtime.Caller(1)
if ok {
absPath = path.Dir(filename)
}
return absPath
}

View File

@@ -241,3 +241,8 @@ func TestListFileNames(t *testing.T) {
expected := []string{"formatter.go", "formatter_example_test.go", "formatter_test.go"}
assert.Equal(expected, filesInPath)
}
func TestCurrentPath(t *testing.T) {
absPath := CurrentPath()
t.Log(absPath)
}