Repository navigation
Conversation
152ac25 to
e5403fd
Compare
e5403fd to
963c366
Compare
When validating paths in the fsnode module, use the `filepath` module instead of the (more generic) `path`.
When we move `ImageConfig` into YAML we will need support for `fsnode.File` as it is used as part of the ImageConfig. This commit adds support for JSON/YAML unmarshaling.
When unmarshaling fsnode.{Dir,File}, also validate that no
extra keys are used.
In the `type Directory struct` we current use: ``` ensureParentDirs bool `rename:"ensure_parent_dirs"` ``` We cannot use a "json" tag here because "go vet" complains that it is used on an unexported field and "go vet" cannot ignore lines. Longer term it is probably worthwhile to refactor this code so that custom unmarshaling is not needed, i.e. just have an unexpored "type directoryJSON" with exported fields and a public method only type (like we have now).
c62377c to
32a0e95
Compare
achilleas-k
left a comment
There was a problem hiding this comment.
Minor comment/question. Otherwise, LGTM.
| // We cannot use a "json" tag here because "go vet" complains | ||
| // that it is used on an unexported field and "go vet" cannot | ||
| // ignore lines. |
There was a problem hiding this comment.
Seems like it might be less trouble to export the field. Shouldn't cause any issues, right?
lzap
left a comment
There was a problem hiding this comment.
Okay, this is not nice but it is what it is. I am not too familiar with this code yet.
But the helper function might be improved, it almost looks like you want it to be generic so a good contract and maybe separating it into its own file (with a test) might be a good option?
|
|
||
| // XXX: ideally we would also check here that we do not | ||
| // get extra/mistyped fields | ||
| var m map[string]interface{} |
There was a problem hiding this comment.
Nitpick, any is so much faster to type.
| var m map[string]interface{} | |
| var m map[string]any |
| } | ||
|
|
||
| // XXX: ideally we would also check here that we do not | ||
| // get extra/mistyped fields |
There was a problem hiding this comment.
Generally, I do not like writing TODOs in the code, I tend too either do stuff or file a ticket. But the codebase is already full of these, so I will just rant about it and that's about it :-)
| collect(val, val.Type()) | ||
|
|
||
| return fieldNames | ||
| } |
There was a problem hiding this comment.
This function contract should take the JSON map as input and only return error, this is way to open for no reason. The details on how this is done should be completely hidden. Speaking of:
Structs usually have just few fields, there is no reason to use map, arrays or slices are usually faster up to dozens of elements than hashing particularly when they need to be built. I suggest to use just slice and use slices.Contain in an unsorted slice which will be faster than building the hash only to look it up few times.
This function really deserves a separate unit test on its own.
Also, this is ugly and I do not understand how we got here. Is this really the only option? Why the field cannot be just exported?
|
Thanks for the feedback - I agree that the map[string]any unmarshaller is not nice (it was quick and expedient as its really just a distraction from my main goal to get the image config into YAML). But I agree we should not compromise on quality! I opened #1500 with an alternative approach that use more buld-in go featurs and will close this one (at least for now). |
More unmarshal support in preparation for the ImageConfig work in #1462 - split to make reviews easier, the fsnode ones are a bit more tricky.
fsnode: validate unknown keys in fsnode.{Dir,File}
When unmarshaling fsnode.{Dir,File}, also validate that no
extra keys are used.
fsnode: add JSON/YAML support for File/Directory
When we move
ImageConfiginto YAML we will need support forfsnode.Fileas it is used as part of the ImageConfig.This commit adds support for JSON/YAML unmarshaling.
fsnode: use
path/filepathinstead ofpathWhen validating paths in the fsnode module, use the
filepathmodule instead of the (more generic)
path.