Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go provides *no native way* to expand Windows env vars #43763

Closed
liquidaty opened this issue Jan 18, 2021 · 0 comments
Closed

Go provides *no native way* to expand Windows env vars #43763

liquidaty opened this issue Jan 18, 2021 · 0 comments

Comments

@liquidaty
Copy link

liquidaty commented Jan 18, 2021

--- update: Retracting this comment. registry.ExpandString is sufficient for our needs, even though it has some limitations as described in #24848

I am re-submitting #5177 and #24848. In particular, there is no built-in function to expand Windows-style env vars (e.g. "%PROGRAMFILES%").

Why does the Go team refuse to fix this? Golang is supposed to support Windows. Forcing Windows users to adopt non-windows conventions is not what "support" means. We can't build a product with Go and then tell our customers' IT teams "You need to change the way that you reference environment vars because the Golang team refuses to recognize "%PROGRAMFILES%" as an environment variable even when running on Windows".

To revisit some points raised before:

"according to docs, os.ExpandEnv will only expand $name and ${name}". Nice to know but does not address the problem. golang could always provide another alternative such as @jeffreydwalter's suggestion to provide e.g. ExpandWinEnv.

"there are alternatives like golang.org/x/sys/windows/registry.ExpandString". Unless something has changed, registry.ExpandString doesn't work for this purpose (see #24848)

"there's an easier workaround here - simply replacing %FOO% with ${FOO}". It is a difficult proposition for anyone developing with Go to tell their corporate clients that they need to remember that just for their product, they need to change the way that they reference environment variables in strings.

We're rolling our own solution for now, but it would be much appreciate if you would reconsider offering some os-package function that provided env var expansion for windows-style conventions (even if it was as simple as a wrapper for the native ExpandEnvironmentStrings function)

@ALTree ALTree changed the title Golang provides *no native way* to expand Windows env vars Go provides *no native way* to expand Windows env vars Jan 22, 2021
@golang golang locked and limited conversation to collaborators Jan 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants