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:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user