jmattheis / goverter

Generate type-safe Go converters by simply defining an interface
https://goverter.jmattheis.de/
MIT License
487 stars 46 forks source link

feat: allow method calls for struct field mappings #99

Closed jmattheis closed 9 months ago

jmattheis commented 9 months ago

Input:

package structs

// goverter:converter
type Converter interface {
    Convert(source Input) Output
}

type Input struct {
    Name string
}
func (Input) Age() int {
    return 42
}
type Output struct {
    Name string
    Age int
}

Output:

// Code generated by github.com/jmattheis/goverter, DO NOT EDIT.

package generated

import execution "github.com/jmattheis/goverter/execution"

type ConverterImpl struct{}

func (c *ConverterImpl) Convert(source execution.Input) execution.Output {
    var structsOutput execution.Output
    structsOutput.Name = source.Name
    structsOutput.Age = source.Age()
    return structsOutput
}

Fixes #91

codecov[bot] commented 9 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (7b15fee) 97.73% compared to head (f91d3e7) 97.79%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #99 +/- ## ========================================== + Coverage 97.73% 97.79% +0.05% ========================================== Files 39 39 Lines 1680 1720 +40 ========================================== + Hits 1642 1682 +40 Misses 26 26 Partials 12 12 ``` | [Files](https://app.codecov.io/gh/jmattheis/goverter/pull/99?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jannis+Mattheis) | Coverage Δ | | |---|---|---| | [builder/default.go](https://app.codecov.io/gh/jmattheis/goverter/pull/99?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jannis+Mattheis#diff-YnVpbGRlci9kZWZhdWx0Lmdv) | `100.00% <100.00%> (ø)` | | | [builder/pointer.go](https://app.codecov.io/gh/jmattheis/goverter/pull/99?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jannis+Mattheis#diff-YnVpbGRlci9wb2ludGVyLmdv) | `100.00% <100.00%> (ø)` | | | [builder/struct.go](https://app.codecov.io/gh/jmattheis/goverter/pull/99?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jannis+Mattheis#diff-YnVpbGRlci9zdHJ1Y3QuZ28=) | `100.00% <100.00%> (ø)` | | | [config/extend.go](https://app.codecov.io/gh/jmattheis/goverter/pull/99?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jannis+Mattheis#diff-Y29uZmlnL2V4dGVuZC5nbw==) | `98.14% <100.00%> (ø)` | | | [config/method.go](https://app.codecov.io/gh/jmattheis/goverter/pull/99?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jannis+Mattheis#diff-Y29uZmlnL21ldGhvZC5nbw==) | `100.00% <100.00%> (ø)` | | | [method/parse.go](https://app.codecov.io/gh/jmattheis/goverter/pull/99?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jannis+Mattheis#diff-bWV0aG9kL3BhcnNlLmdv) | `96.07% <100.00%> (+0.16%)` | :arrow_up: | | [xtype/tocode.go](https://app.codecov.io/gh/jmattheis/goverter/pull/99?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jannis+Mattheis#diff-eHR5cGUvdG9jb2RlLmdv) | `97.08% <100.00%> (+0.05%)` | :arrow_up: | | [xtype/type.go](https://app.codecov.io/gh/jmattheis/goverter/pull/99?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jannis+Mattheis#diff-eHR5cGUvdHlwZS5nbw==) | `97.27% <100.00%> (+0.45%)` | :arrow_up: |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.