forked from containers/toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/list: Decode toolbox image/container JSONs to typed structs
Every time Podman changes their JSON API Toolbox breaks horribly. That is caused by the combination of decoding the JSON purely by hand and by the complete lack of type assertions to make the process stable. I previously didn't know that unmarshalling with Go works on the 'do the best job it can' logic (thank you Owen!). This makes the need to check for subtle changes in the names of fields go away and type checking a bit more bareable (marking the questioned field as interface{} and then immediatelly type switch). If even now an existing field does not hold an expected value the field will remain blank. To take this a bit further, I created two types (toolboxImage and toolboxContainer) that are used by both functions for returning the list of images and containers. Instead of using getters for properties that need some checks or adjustments this uses a custom unmarshaling function (Owen's idea; thanks!). The work around populating the two new types is a bit hacky (marshalling and already unmarshalled JSON - that was unmarshalled to []map[string]interface{} - that is then unmarshalled to either toolboxImage or toolboxContainer. This is done to prevent a major refactoring before the 0.1.0 release. This should be changed for the 0.2.0 release. containers#503
- Loading branch information
1 parent
583a82d
commit 770bfd0
Showing
2 changed files
with
146 additions
and
66 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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