Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gohcl: enable customizing decoding with decode options #705

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jsternberg
Copy link

Adds a struct DecodeOptions that can be used to customize some of the behavior of DecodeBody and DecodeExpression.

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#2758

We'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 custom ImpliedType 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.

Adds a struct `DecodeOptions` that can be used to customize some of the
behavior of `DecodeBody` and `DecodeExpression`.

This allows customizing the behavior of determining the implied type
from a Go type and customizing the behavior of converting between cty
types.
Copy link

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

1 similar comment
Copy link

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants