-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
475 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Input and output formats | ||
|
||
Goverter supports three different input output format combinations. This guide | ||
is for you to decide the formats you want to use. All examples have this in | ||
common. | ||
|
||
[[toc]] | ||
|
||
## interface to struct | ||
|
||
This is the default when using | ||
[`goverter:converter`](../reference/converter.md). | ||
|
||
**Pros**: | ||
|
||
- All goverter features are supported | ||
- The interface is usable before goverter generated the implementation. | ||
- reduces the occurence of compile errors because of missing or outdated | ||
generated implementation. | ||
- allows using generated methods in custom methods | ||
|
||
**Cons**: | ||
|
||
- You need to initialize the implementation. | ||
- You need to call methods on the struct to execute conversions | ||
|
||
::: details Example (click me) | ||
::: code-group | ||
<<< @../../example/format/interfacetostruct/input.go | ||
<<< @../../example/format/common/common.go | ||
<<< @../../example/format/interfacetostruct/generated/generated.go [generated/generated.go] | ||
::: | ||
|
||
## variables to assign-variable | ||
|
||
This is the default when using | ||
[`goverter:variables`](../reference/converter.md). | ||
|
||
**Pros**: | ||
|
||
- All goverter features are supported. | ||
- The variables are usable before goverter generated the implementation. | ||
- reduces the occurence of compile errors because of missing or outdated | ||
generated implementation. | ||
- allows using generated functions in custom methods | ||
- You can execute conversions directly without having to initializing a struct | ||
|
||
**Cons**: | ||
|
||
- Possible runtime overhead when Go cannot optimizen variables the same as | ||
functions. Benchmark your use-case, if speed is really important to you. | ||
|
||
::: details Example (click me) | ||
::: code-group | ||
<<< @../../example/format/assignvariables/input.go | ||
<<< @../../example/format/common/common.go | ||
<<< @../../example/format/assignvariables/input.gen.go | ||
::: | ||
|
||
## interface to functions | ||
|
||
**Pros**: | ||
|
||
- You can execute conversions directly without having to initializing a struct | ||
|
||
**Cons**: | ||
|
||
- The interface is only used for defining the conversions and is otherwise not | ||
usable | ||
- The use-case [`map` method with converter](../reference/map.md#method-with-converter) is | ||
unsupported without replacement. | ||
|
||
::: details Example (click me) | ||
::: code-group | ||
<<< @../../example/format/interfacefunction/input.go | ||
<<< @../../example/format/common/common.go | ||
<<< @../../example/format/interfacefunction/generated/generated.go | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Setting: converter | ||
|
||
`variables` accepts no arguments and can be defined as [converter | ||
comment](./define-settings.md#converter). | ||
|
||
`variables` instructs goverter to generate an implementation for the given | ||
variables. You can have multiple variables blocks in one package. | ||
|
||
See [output](./output.md) to control the output location/package of the | ||
generated converter. | ||
|
||
::: code-group | ||
<<< @../../example/format/assignvariables/input.go | ||
<<< @../../example/format/common/common.go | ||
<<< @../../example/format/assignvariables/input.gen.go | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.