草庐IT

EvalSymlinks

全部标签

unit-testing - 如何为单元测试模拟标准包函数

我有三个功能:funcIsSymlinks(pathstring){......}func(c*MyClass)myFunc1(pathstring){...morecode...morecodeifIsSymlinks(path){realPath:=filepath.EvalSymlinks(path)}...morecode...morecode}funcmyFunc2(pathstring){...morecode...morecodeifIsSymlinks(path){realPath:=filepath.EvalSymlinks(path)}...morecode...m

go - 在 Go 中解析符号链接(symbolic link)

我如何解析Go中的符号链接(symboliclink)?目前我调用readlink-f但我想要一些更惯用的东西。packagemainimport("os/exec""fmt")funcresolve(pstring)string{cmd:=exec.Command("readlink","-f",p)out,_:=cmd.Output()return(string(out))}funcmain(){fmt.Printf(resolve("/initrd.img"))} 最佳答案 参见filepath.EvalSymlinks().

go - 在 Go 中解析符号链接(symbolic link)

我如何解析Go中的符号链接(symboliclink)?目前我调用readlink-f但我想要一些更惯用的东西。packagemainimport("os/exec""fmt")funcresolve(pstring)string{cmd:=exec.Command("readlink","-f",p)out,_:=cmd.Output()return(string(out))}funcmain(){fmt.Printf(resolve("/initrd.img"))} 最佳答案 参见filepath.EvalSymlinks().