Skip to content

Commit dabcefb

Browse files
author
Tit Petric
committed
go-fsck: Update docs to not output unexported receiver funcs
1 parent f762e4e commit dabcefb

File tree

7 files changed

+126
-1
lines changed

7 files changed

+126
-1
lines changed

cmd/go-fsck/Taskfile.yml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ tasks:
2121
desc: "Build example"
2222
cmds:
2323
- go-fsck extract --verbose --include-tests --include-sources -i example/ -o example/go-fsck.json --pretty-json
24+
- cd example && go-fsck docs > README.md && cd ..
2425

2526
restore:
2627
desc: "Restore from model"

cmd/go-fsck/example/README.md

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Package example
2+
3+
```go
4+
import (
5+
"github.com/TykTechnologies/exp/cmd/go-fsck/example"
6+
}
7+
```
8+
9+
Example package doc.
10+
11+
## Types
12+
13+
```go
14+
// Allocator holds a sync.Pool of objects of type T.
15+
type Allocator[T Reseter] struct {
16+
pool sync.Pool
17+
}
18+
```
19+
20+
```go
21+
// Body represends a decoded body
22+
type Body struct {
23+
Name string
24+
}
25+
```
26+
27+
```go
28+
// File represents a filename
29+
type File string
30+
```
31+
32+
```go
33+
// Reseter is the interface that types must implement to be managed by Allocator.
34+
type Reseter interface {
35+
Reset()
36+
}
37+
```
38+
39+
## Consts
40+
41+
```go
42+
// Const comment
43+
const E_WARNING = "warning" // const line comment
44+
```
45+
46+
## Function symbols
47+
48+
- `func GlobalFunc () error`
49+
- `func New (newFunc func() T) *Allocator[T]`
50+
- `func (*Allocator[T]) Get () T`
51+
- `func (*Allocator[T]) Put (t T)`
52+
53+
### GlobalFunc
54+
55+
Global func comment
56+
57+
```go
58+
func GlobalFunc () error
59+
```
60+
61+
### New
62+
63+
New creates an Allocator for type T using the provided constructor.
64+
65+
```go
66+
func New (newFunc func() T) *Allocator[T]
67+
```
68+
69+
### Get
70+
71+
Get retrieves an object from the internal pool.
72+
73+
```go
74+
func (*Allocator[T]) Get () T
75+
```
76+
77+
### Put
78+
79+
Put returns an object to the pool after resetting it.
80+
81+
```go
82+
func (*Allocator[T]) Put (t T)
83+
```
84+
85+

cmd/go-fsck/example/go-fsck.json

+19
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@
4646
"Doc": "Reseter is the interface that types must implement to be managed by Allocator.",
4747
"Name": "Reseter",
4848
"Source": "// Reseter is the interface that types must implement to be managed by Allocator.\ntype Reseter interface {\n\tReset()\n}"
49+
},
50+
{
51+
"Kind": "type",
52+
"File": "internal.go",
53+
"SelfContained": true,
54+
"Name": "logger",
55+
"Source": "type logger struct {\n\tout []string\n}"
4956
}
5057
],
5158
"Consts": [
@@ -136,6 +143,18 @@
136143
],
137144
"Signature": "Put (t T)",
138145
"Source": "// Put returns an object to the pool after resetting it.\nfunc (a *Allocator[T]) Put(t T) {\n\tt.Reset()\n\ta.pool.Put(t)\n}"
146+
},
147+
{
148+
"Kind": "func",
149+
"File": "internal.go",
150+
"SelfContained": false,
151+
"Name": "Log",
152+
"Receiver": "*logger",
153+
"Arguments": [
154+
"string"
155+
],
156+
"Signature": "Log (s string)",
157+
"Source": "func (l *logger) Log(s string) {\n\tl.out = append(l.out, s)\n}"
139158
}
140159
]
141160
},

cmd/go-fsck/example/internal.go

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package example
2+
3+
type logger struct {
4+
out []string
5+
}
6+
7+
func (l *logger) Log(s string) {
8+
l.out = append(l.out, s)
9+
}

cmd/go-fsck/model/declaration.go

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ func (d *Declaration) HasName(find string) bool {
3838
}
3939

4040
func (d *Declaration) IsExported() bool {
41+
if d.Receiver != "" && !ast.IsExported(strings.TrimLeft(d.Receiver, "*")) {
42+
return false
43+
}
44+
4145
for _, name := range d.Names {
4246
if ast.IsExported(name) {
4347
return true

cmd/go-fsck/model/restored/declaration.go

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ func (d *Declaration) HasName(find string) bool {
4545
}
4646

4747
func (d *Declaration) IsExported() bool {
48+
if d.Receiver != "" && !ast.IsExported(strings.TrimLeft(d.Receiver, "*")) {
49+
return false
50+
}
51+
4852
for _, name := range d.Names {
4953
if ast.IsExported(name) {
5054
return true

cmd/go-fsck/model/restored/go-fsck.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@
131131
"References": {
132132
"ast": [
133133
"IsExported"
134+
],
135+
"strings": [
136+
"TrimLeft"
134137
]
135138
},
136139
"Name": "IsExported",
@@ -139,7 +142,7 @@
139142
"bool"
140143
],
141144
"Signature": "IsExported () bool",
142-
"Source": "func (d *Declaration) IsExported() bool {\n\tfor _, name := range d.Names {\n\t\tif ast.IsExported(name) {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn ast.IsExported(d.Name)\n}"
145+
"Source": "func (d *Declaration) IsExported() bool {\n\tif d.Receiver != \"\" \u0026\u0026 !ast.IsExported(strings.TrimLeft(d.Receiver, \"*\")) {\n\t\treturn false\n\t}\n\n\tfor _, name := range d.Names {\n\t\tif ast.IsExported(name) {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn ast.IsExported(d.Name)\n}"
143146
},
144147
{
145148
"Kind": "func",

0 commit comments

Comments
 (0)