You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As of right now, os (and by extension, filepath) package exports os.PathSeparator and os.PathListSeparator constants that are tied to the system the binary is built on (by //go:build constraints). So, for example, on unix systems, these would be / and :. The problem with this approach is that there is no way to reference a Windows separator from a unix-built binary, and vice versa. While this might be a rare occasion, sometimes there is a need for that (i.e. if some unix-style binary requires unix-style separators even when executed in Windows environment, or if you need to render a help docstring for the user).
Of course, you can always get around this and just declare your own separators but that just feels hacky when there is an exposed const in the standard package.
I'd be happy to submit a PR for this
Proposed changes
What i propose is adding new constants to the os package that would reference each style, and only typealiasing them in _<os>.go files. This will not break existing external API, only expose new constants (that are already present in the library, but just not exposed due to build constraints).
seankhliao
changed the title
proposal: expose all possible path and pathlist separators in os package
proposal: os: expose all possible path and pathlist separators
Feb 24, 2023
Description
As of right now,
os
(and by extension,filepath
) package exportsos.PathSeparator
andos.PathListSeparator
constants that are tied to the system the binary is built on (by //go:build constraints). So, for example, on unix systems, these would be/
and:
. The problem with this approach is that there is no way to reference a Windows separator from a unix-built binary, and vice versa. While this might be a rare occasion, sometimes there is a need for that (i.e. if some unix-style binary requires unix-style separators even when executed in Windows environment, or if you need to render a help docstring for the user).Of course, you can always get around this and just declare your own separators but that just feels hacky when there is an exposed const in the standard package.
I'd be happy to submit a PR for this
Proposed changes
What i propose is adding new constants to the
os
package that would reference each style, and only typealiasing them in_<os>.go
files. This will not break existing external API, only expose new constants (that are already present in the library, but just not exposed due to build constraints).In
os
package:The text was updated successfully, but these errors were encountered: