go filepath Abs

func Abs(path string) (string, error) golang

檢測地址是不是絕對地址,是絕對地址直接返回,不是絕對地址,會添加當前工做路徑到參數path前,而後返回 測試

一下是測試代碼 spa

func TestAbs() {
    fpt, err := filepath.Abs("/hello")
    if err != nil {
        panic(err)
    }
    fmt.Println(fpt) string

    fpt, err = filepath.Abs("helleeo")
    if err != nil {
        panic(err)
    }
    fmt.Println(fpt)
} test

打印信息: file

/hello
/home/xxx/workspace/gotestworkspace/golangtest/helleeo error

「/」表示當前路徑下 工作

相關文章
相關標籤/搜索