-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
doc.go
86 lines (67 loc) · 4.26 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// MIT License
//
// Copyright (c) 2022-2023 HANAI Tohru
/*
Convergen is a code generator that creates functions for type-to-type copy.
It generates functions that copy field to field between two types.
Notation Table
--------------
| notation | location | summary |
|-------------------------------------------|--------------------|---------------------------------------------------------------------------------------|
| :match <`name` | `none`> | interface, method | Sets the field matcher algorithm (default: `name`). |
| :style <`return` | `arg`> | interface, method | Sets the style of the assignee variable input/output (default: `return`). |
| :recv <_var_> | method | Specifies the source value as a receiver of the generated function. |
| :reverse | method | Reverses the copy direction. Might be useful with receiver form. |
| :case | interface, method | Sets case-sensitive for name match (default). |
| :case:off | interface, method | Sets case-insensitive for name match. |
| :getter | interface, method | Includes getters for name match. |
| :getter:off | interface, method | Excludes getters for name match (default). |
| :stringer | interface, method | Calls String() if appropriate in name match. |
| :stringer:off | interface, method | Calls String() if appropriate in name match (default). |
| :typecast | interface, method | Allows type casting if appropriate in name match. |
| :typecast:off | interface, method | Suppresses type casting if appropriate in name match (default). |
| :skip <_dst field pattern_> | method | Marks the destination field to skip copying. Regex is allowed in /…/ syntax. |
| :map <_src_> <_dst field_> | method | the pair as assign source and destination. |
| :conv <_func_> <_src_> [_to field_] | method | Converts the source value by the converter and assigns its result to the destination. |
| :literal <_dst_> <_literal_> | method | Assigns the literal expression to the destination. |
| :preprocess <_func_> | method | Calls the function at the beginning of the convergen func. |
| :postprocess <_func_> | method | Calls the function at the end of the convergen function. |
Installation and Introduction
-----------------------------
### Use as a Go generator
To use Convergen as a Go generator, install the module in your Go project directory via go get:
```shell
$ go get -u github.com/reedom/convergen@latest
```
Then, write a generator as follows:
```go
//go:generate go run github.com/reedom/convergen@v0.6.1
type Convergen interface {
…
}
````
### Use as a CLI command
To use Convergen as a CLI command, install the command via go install:
```shell
$ go install github.com/reedom/convergen@latest
```
You can then generate code by calling:
```shell
$ convergen any-codegen-defined-code.go
```
The CLI help shows:
```shell
Usage: convergen [flags] <input path>
By default, the generated code is written to <input path>.gen.go
Flags:
-dry
Perform a dry run without writing files.
-log
Write log messages to <output path>.log.
-out string
Set the output file path.
-print
Print the resulting code to STDOUT as well.
```
*/
package main