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

Is there a supported way of specifying per-OS defaults? #162

Open
m90 opened this issue Jan 13, 2020 · 1 comment
Open

Is there a supported way of specifying per-OS defaults? #162

m90 opened this issue Jan 13, 2020 · 1 comment

Comments

@m90
Copy link

m90 commented Jan 13, 2020

I am building an application that supports Unix-like OSes and Windows. In my configuration definition I am storing certain file paths like:

type Config struct {
     SomeLocation string `default:"/etc/myapp"`
}

This default obviously won't work on Windows where I would need to have something like:

type Config struct {
     SomeLocation string `default:"%AppData%\myapp"`
}

The approach I am using right now is having a config_unix.go and config_windows.go which have the respective build tags. This solution is very brittle and repetitive as I need to make sure the two config type definitions are always in sync.

Is this scenario something that package envconfig supports or could support? Is there a better approach for solving my problem using conditional compilation?

@abemedia
Copy link

If I was you I'd just have one single config struct and set that default value elsewhere. For example you could prepopulate that value before calling Process and if it's set in the config it simply gets overwritten.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants