我可以强制filepath.Abs​​给出为其他操作系统设计的路径吗?

I currently am working on Windows. I use the following code to get an absolute path for a relative path.

absolutePath, err := filepath.Abs(relativePath)

The output for this is C:\project\test. Is there any way to "trick" filepath.Abs to have a Linux style absolute path, whether it's /project/test or /d/project/test/? Thanks!

As @JimB noted, converting a relative path to an absolute path is not only OS-specific, it's context-specific: the same relative path on different systems (regardless of OS) can yield different paths; in fact, even on the same system, converting relative to absolute from different working directories can yield different paths. Again as @JimB noted, you can use path.Clean to remove any unnecessary or reduntant relative path components (e.g. turn /dir/../otherDir/./subDir/ into /otherDir/subDir/), but that's the closest you'll get to anything not context-sensitive.

If you just want to convert the representation, there's filepath.ToSlash which will replace all platform-specific separators with forward slashes. If you're trying to re-use a path across systems, you could run ToSlash on the input, store the "generic" path using forward slashes, then on the target system use filepath.FromSlash to convert it back to the platform-specific path separator.