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

Add configuration options to NewFactValue #260

Merged
merged 6 commits into from
Sep 26, 2023

Conversation

arbulu89
Copy link
Contributor

@arbulu89 arbulu89 commented Sep 26, 2023

Create NewFactValueWithConf to enable configuration of the NewFactValue function.
Initially only SnakeCaseKeys and StringConversion options are added

@arbulu89 arbulu89 force-pushed the new-fact-value-string-conversion branch from 8c1c86d to 7e68407 Compare September 26, 2023 06:51
@arbulu89 arbulu89 marked this pull request as ready for review September 26, 2023 07:06
Copy link
Member

@CDimonaco CDimonaco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for the logic,

Just a couple of comments on the code style.

We can also use the functional options pattern, having in the end something more ideomatic like

NewFactValue(thingstocast, WithSnakeCase(), WithStringCasting()) or NewFactValue(thingstocast) without any additional configuration, having the options as variadic arguments.

But this is up to you, we have two options for now, so as you wish.

The only things I request to change are in the comments.

Some examples of functional options pattern: https://charlesxu.io/go-opts/

if err != nil {
return nil, err
}
if conf.SnakeCaseKeys {
key = strcase.ToSnake(key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use a new scoped variable, not assigning to the key moving pointer in the for loop?

pkg/factsengine/entities/fact_value.go Outdated Show resolved Hide resolved
pkg/factsengine/entities/fact_value.go Outdated Show resolved Hide resolved
@arbulu89 arbulu89 force-pushed the new-fact-value-string-conversion branch from 538d825 to e044965 Compare September 26, 2023 09:57
Copy link
Member

@CDimonaco CDimonaco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@rtorrero rtorrero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

stringConversion bool
}

type FactValuOption func(f *conf)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean FactValueOption here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes XD

@arbulu89 arbulu89 force-pushed the new-fact-value-string-conversion branch from 381563a to 52b9988 Compare September 26, 2023 12:01
@arbulu89 arbulu89 merged commit 2737a89 into main Sep 26, 2023
10 checks passed
@arbulu89 arbulu89 deleted the new-fact-value-string-conversion branch September 26, 2023 13:34
@arbulu89 arbulu89 added the enhancement New feature or request label Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

None yet

3 participants