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

cleanup: Use generics to simplify code for parse_config and related builtins #857

Merged
merged 1 commit into from
Aug 31, 2023

Conversation

jalseth
Copy link
Member

@jalseth jalseth commented Aug 29, 2023

No description provided.

@jalseth jalseth force-pushed the builtin-refactor branch 2 times, most recently from 06b5675 to 9c4643b Compare August 29, 2023 01:45
Copy link
Member

@boranx boranx left a comment

Choose a reason for hiding this comment

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

lgtm

Thanks for the refactor and switching to the generics
What about refactoring the other places as well? (like engine or parser)

@jalseth
Copy link
Member Author

jalseth commented Aug 31, 2023

I think they could be used in parser, as a lot of logic that package is:

  1. Unmarshal []byte from format XYZ to struct
  2. Marshal struct to JSON
  3. Unmarshal from JSON to map[string]any for use with OPA

This could be written generically as Parse[T any](data []byte, func(data []byte, temp T) error) (map[string]any, error) which would accept the data and an config-specific unmarshal function (step 1) and then steps 2 and 3 are the same regardless of config.

@jalseth
Copy link
Member Author

jalseth commented Aug 31, 2023

Opened #861 to discuss this further

@jalseth jalseth merged commit fe4c225 into master Aug 31, 2023
7 checks passed
@jalseth jalseth deleted the builtin-refactor branch August 31, 2023 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants