Skip to content

Commit 9e47b21

Browse files
authored
docs: add a pointer receiver example (#117)
1 parent 595d087 commit 9e47b21

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,24 @@ The same can be done via the `-fn=<name:tag:arg-pos>` flag when using `musttag`
8989
musttag -fn="github.com/hashicorp/hcl/v2/hclsimple.DecodeFile:hcl:2" ./...
9090
```
9191

92+
To report a custom function that works with a pointer to the struct, you need to add its description to `.golangci.yml`.
93+
The following is an example of adding support for [`validate.Struct`][12]:
94+
95+
```yaml
96+
linters-settings:
97+
musttag:
98+
functions:
99+
- name: (*github.com/go-playground/validator/v10.Validate).Struct
100+
tag: validate
101+
arg-pos: 0
102+
```
103+
104+
The same can be done via the `-fn=<name:tag:arg-pos>` flag when using `musttag` standalone:
105+
106+
```shell
107+
musttag -fn="(*github.com/go-playground/validator/v10.Validate).Struct:validate:0" ./...
108+
```
109+
92110
[1]: https://github.com/uber-go/guide/blob/master/style.md#use-field-tags-in-marshaled-structs
93111
[2]: https://pkg.go.dev/encoding/json
94112
[3]: https://pkg.go.dev/encoding/xml
@@ -100,3 +118,4 @@ musttag -fn="github.com/hashicorp/hcl/v2/hclsimple.DecodeFile:hcl:2" ./...
100118
[9]: https://github.com/go-simpler/musttag/releases
101119
[10]: https://golangci-lint.run/usage/linters/#musttag
102120
[11]: https://pkg.go.dev/github.com/hashicorp/hcl/v2/hclsimple#Decode
121+
[12]: https://pkg.go.dev/github.com/go-playground/validator/v10#Validate.Struct

0 commit comments

Comments
 (0)