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.
Description
This PR switches vtadmin
FileConfig.Set
to use viper to load configs.This issue does a good job explaining the why behind this
admittedly-hacky code. What I would have preferred to do is add
UnmarshalJSON
,UnmarshalTOML
, (and so on) methods to bothFileConfig
andConfig
, but switching to viper means we don't invokethose custom unmarshalers at all, because viper is going from
$file_bytes=>
map[string]interface{}
=(via mapstructure)>$your_type.So, we define a temporary struct (so far, so good) that will play nicely
with mapstructure's unmarshaling. We then take those string maps and
hand them off to the individual Config structs to run through the
kv-
parseOne
loop as before.Since we're using viper to load from files now (and viper does not
invoke our custom unmarshal functions ...), we no longer need them, so I
deleted all of that code as well.
This now means we support loading JSON/TOML/HCL configs in addition to YAML.
Related Issue(s)
vitessio/enhancements#8
Checklist
I also started the local vtadmin with both yaml and json config files, works as expected.
Deployment Notes