mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-11-24 08:47:04 +08:00
完善功能
This commit is contained in:
25
utils/file.go
Normal file
25
utils/file.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"os"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func AbsolutePath(p string) (string,error) {
|
||||
|
||||
if strings.HasPrefix(p, "~") {
|
||||
home := os.Getenv("HOME")
|
||||
if home == "" {
|
||||
panic(fmt.Sprintf("can not found HOME in envs, '%s' AbsPh Failed!", p))
|
||||
}
|
||||
p = fmt.Sprint(home, string(p[1:]))
|
||||
}
|
||||
s, err := filepath.Abs(p)
|
||||
|
||||
if nil != err {
|
||||
return "",err
|
||||
}
|
||||
return s,nil
|
||||
}
|
||||
Reference in New Issue
Block a user