gohcl: enable customizing decoding with decode options #705
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.
Adds a struct
DecodeOptions
that can be used to customize some of the behavior ofDecodeBody
andDecodeExpression
.This allows customizing the behavior of determining the implied type from a Go type and customizing the behavior of converting between cty types.
This is part of some work for the
docker buildx bake
command: docker/buildx#2758We'd like some specialized convert logic so we can have a type be either in a string format or a more structured object format. The easiest way we've found to do this is to utilize capsule types and override the
ImpliedType
function. We can then add a customImpliedType
function to recognize specific types and insert a capsule type instead of the default implied type.While this change also allows customizing
Convert
, I found that method much harder to modify. The implementation was much more involved and would require more code to be duplicated due to nested types.