两者的文档和代码看起来是一样的。 为什么有两个重复的函数?
最佳答案
它们不是“重复项”,它们是不同包的一部分,因此您应该在它们包的上下文中检查和解释它们。
包裹path
“实现操作斜杠分隔路径的实用程序”独立于平台/操作系统。
包裹path/filepath
“实现以与目标操作系统定义的文件路径兼容的方式操作文件名路径的实用程序”。
因此,例如 path/filepath
处理操作系统之间的路径分隔符差异。
如果您仔细查看 filepath.Match()
的文档, 它结束于:
On Windows, escaping is disabled. Instead, '\' is treated as path separator.
并且还存在术语解释差异。 path.Match()
:
term:
'*' matches any sequence of non-/ characters
'?' matches any single non-/ character
和filepath.Match()
:
term:
'*' matches any sequence of non-Separator characters
'?' matches any single non-Separator character
关于go - path.Match 和 filepath.Match 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50637904/