-
Notifications
You must be signed in to change notification settings - Fork 385
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
Possible to populate fields discretely for a slice of structs? #169
Comments
colega
added a commit
to colega/envconfig
that referenced
this issue
Mar 19, 2020
Solves kelseyhightower#169 Enables population of a slice of structs, in the most expected way: MYAPP_SLICE_0_FOO=foo MYAPP_SLICE_0_BAR=bar MYAPP_SLICE_1_FOO=foo MYAPP_SLICE_1_BAR=bar Would fill a slice of []struct{Foo, Bar string} Usage printout also supports this slices, printing them as a single MYAPP_SLICE_[N]_FOO MYAPP_SLICE_[N]_BAR Variables to be filled, which should be understood as slices with numerical indexes.
colega
added a commit
to colega/envconfig
that referenced
this issue
Mar 19, 2020
Solves kelseyhightower#169 Enables population of a slice of structs, in the most expected way: MYAPP_SLICE_0_FOO=foo MYAPP_SLICE_0_BAR=bar MYAPP_SLICE_1_FOO=foo MYAPP_SLICE_1_BAR=bar Would fill a slice of []struct{Foo, Bar string} Usage printout also supports this slices, printing them as a single MYAPP_SLICE_[N]_FOO MYAPP_SLICE_[N]_BAR Variables to be filled, which should be understood as slices with numerical indexes.
colega
added a commit
to colega/envconfig
that referenced
this issue
Apr 27, 2020
Solves kelseyhightower#169 Enables population of a slice of structs, in the most expected way: MYAPP_SLICE_0_FOO=foo MYAPP_SLICE_0_BAR=bar MYAPP_SLICE_1_FOO=foo MYAPP_SLICE_1_BAR=bar Would fill a slice of []struct{Foo, Bar string} Usage printout also supports this slices, printing them as a single MYAPP_SLICE_[N]_FOO MYAPP_SLICE_[N]_BAR Variables to be filled, which should be understood as slices with numerical indexes.
colega
added a commit
to colega/envconfig
that referenced
this issue
Apr 27, 2020
Solves kelseyhightower#169 Enables population of a slice of structs, in the most expected way: MYAPP_SLICE_0_FOO=foo MYAPP_SLICE_0_BAR=bar MYAPP_SLICE_1_FOO=foo MYAPP_SLICE_1_BAR=bar Would fill a slice of []struct{Foo, Bar string} Usage printout also supports this slices, printing them as a single MYAPP_SLICE_[N]_FOO MYAPP_SLICE_[N]_BAR Variables to be filled, which should be understood as slices with numerical indexes.
Could you implement Setter and do it yourself? something like: type cfg struct {
Stuff StuffSlice
}
type StuffSlice []SecondLevelConfig
func (ss *StuffSlice) Set(data string) error {
return json.Unmarshal([]byte(data), &ss)
} EDIT: This doesnt fit your desired env var format, but does allow slice of structs |
hi, would love to see #170 merged - is there any progress planned on that? |
any progress ? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there, and thanks very much for
envconfig
, we love it!One thing I'm not clear on whether or not is possible, and it has come up as a bit of a blocker for us, is say we have a slice of structs as one field in our base config struct, can we set different values on the fields of different structs in the slice?
For example:
Can we put something like
PREFIX_FIELDONE_0_FIELDTWO="string on first struct"
andPREFIX_FIELDONE_1_FIELDTWO="string on second struct"
into the environment, call.Process("PREFIX", &FirstLevelConfig)
and end up with two structs?The text was updated successfully, but these errors were encountered: