Function to convert Go struct back to config.Value#935
Merged
Conversation
config.Value
mgyucht
reviewed
Nov 2, 2023
Contributor
mgyucht
left a comment
There was a problem hiding this comment.
Hm, I'm curious. If we can convert a go struct into config.Value, what would be the difference between this and Merge(ref, ConvertToConfigValue(src))? It might actually be about the same?
| // Dereference pointer if necessary | ||
| for srcv.Kind() == reflect.Pointer { | ||
| if srcv.IsNil() { | ||
| return config.NilValue, nil |
Contributor
There was a problem hiding this comment.
Should we return ref here instead?
Contributor
Author
There was a problem hiding this comment.
No; if the Go structure has nilled a pointer that wasn't nil before, it means that chunk of configuration (or pointer to primitive value) is no longer valid and should not show up in the returned config.Value.
Contributor
Author
|
Good point! It comes close but is not the same. Two differences come to mind:
|
andrewnester
approved these changes
Nov 7, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
This PR is the counterpart to #904. With this change, we are able to convert a
config.Valueinto a Go struct, make modifications to the Go struct, and reflect those changes in a newconfig.Value.This functionality allows us to incrementally introduce this configuration representation to existing bundle mutators. Bundle mutators expect a
*bundle.Bundleargument and mutate its configuration directly. These mutations are not reflected in the correspondingconfig.Value(once introduced), which means we cannot use theconfig.Valueas source of truth until we update all mutators. To address this, we can runconvert.ToTypedandconvert.FromTypedat the mutator boundary (frombundle.Apply) and capture changes made to the Go struct. Then we can incrementally make mutators aware of theconfig.Valueconfiguration and have them mutate that structure directly.Tests
New unit tests pass.
Manual spot checks against the bundle configuration type.