文件或目录的常用变量名称是“路径”。不幸的是,这也是 Go 中一个包的名称。此外,将路径更改为 DoIt 中的参数名称,如何编译此代码?
package main
import (
"path"
"os"
)
func main() {
DoIt("file.txt")
}
func DoIt(path string) {
path.Join(os.TempDir(), path)
}
我得到的错误是:
$6g pathvar.go
pathvar.go:4: imported and not used: path
pathvar.go:13: path.Join undefined (type string has no field or method Join)