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

Expand reflection options behavior. #8

Merged
merged 4 commits into from
Mar 16, 2025

Conversation

fr33r
Copy link
Collaborator

@fr33r fr33r commented Mar 15, 2025

Description

These changes automatically expend reflection option behavior such that:

  • by default, all methods that start with "Set" will be excluded.
    • as outlined in Effective Go, setters should start with "Set", and setters are not eligible for this reflection behavior.
  • a new options, WithColumnNameMapping, can be provided to override the default name determined for a column.

Rationale

  • Without WithColumnNameMapping, the only way specify a custom name is by constructing the entire column definition (either through code or via file definition). This makes it far more convenient.
  • Using Effective Go as a guide, we are able to safely exclude methods that would conventionally be identified as "setters" from being included within the reflection process.

Suggested Version

v1.2.0

Example Usage

obj := Foo{
  FirstName: "Han",
  LastName: "Solo",
}

table, err := morph.Reflect(obj, morph.WithColumnNameMapping("FirstName", "given_name"))
if err != nil {
  panic(err)
}

@fr33r fr33r marked this pull request as ready for review March 16, 2025 03:29
@fr33r fr33r self-assigned this Mar 16, 2025
@fr33r fr33r merged commit d99a9b8 into master Mar 16, 2025
4 checks passed
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.

1 participant