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

Use functional options for resourcex.Unmarshal #199

Open
danielrbradley opened this issue Mar 20, 2024 · 1 comment
Open

Use functional options for resourcex.Unmarshal #199

danielrbradley opened this issue Mar 20, 2024 · 1 comment
Labels
enhancement New feature or request impact/breaking Fixing this issue will require a breaking change impact/usability Something that impacts users' ability to use the product easily and intuitively kind/enhancement Improvements or new features

Comments

@danielrbradley
Copy link
Member

Currently, the call normally looks like:

res, err := resourcex.Unmarshal(&typedInputs, inputs, resourcex.UnmarshalOptions{})

This would be a little neater if using functional arguments such as

func resourcex.Unmarshal(target interface{}, props resource.PropertyMap, opts... resourcex.UnmarshalOption) (resourcex.UnmarshalResult, error)

as then the minimal usage would be:

res, err := resourcex.Unmarshal(&typedInputs, inputs)

This would also avoid possible breaking changes on the public interface later on.

@danielrbradley danielrbradley added enhancement New feature or request impact/breaking Fixing this issue will require a breaking change impact/usability Something that impacts users' ability to use the product easily and intuitively kind/enhancement Improvements or new features labels Mar 20, 2024
@iwahbe
Copy link
Member

iwahbe commented Mar 25, 2024

I'm not 100% sure I agree here. Passing several options looks like this now:

res, err := resourcex.Unmarshal(&typedInputs, inputs, resourcex.UnmarshalOptions{
    ForbidSecrets: true,
    RelaxTyping: true,
    AttemptMagic: true,    
})

I think ☝️ looks cleaner then:

res, err := resourcex.Unmarshal(&typedInputs, inputs,
    resourcex.ForbidSecrets,
    resourcex.RelaxTyping,
    resourcex.AttemptMagic,
})

Neither options are breaking. I think the big win is being able to call resourcex.Unmarshal(&typedInputs, inputs) as is. The loss is the trivially inspectable and portable bundle of options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request impact/breaking Fixing this issue will require a breaking change impact/usability Something that impacts users' ability to use the product easily and intuitively kind/enhancement Improvements or new features
Projects
None yet
Development

No branches or pull requests

2 participants