Skip to content

Commit 9eec6a7

Browse files
committed
gen-accessors: skip unexported field or structs
1 parent 96efd17 commit 9eec6a7

File tree

2 files changed

+14
-199
lines changed

2 files changed

+14
-199
lines changed

github/gen-accessors.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,7 @@ var (
5050
// this blacklist lists structs for which we don't want to generate
5151
// accessors.
5252
blacklistStruct = map[string]bool{
53-
"Client": true,
54-
"service": true,
55-
}
56-
// this blacklist lists fields for which we don't want to generate
57-
// accessors.
58-
blacklistField = map[string]bool{
59-
"client": true,
53+
"Client": true,
6054
}
6155
)
6256

@@ -107,6 +101,16 @@ func (t *templateData) processAST(f *ast.File) error {
107101
if !ok {
108102
continue
109103
}
104+
// skip unexported identifiers
105+
if !ts.Name.IsExported() {
106+
logf("Struct %v is unexported; skipping.", ts.Name)
107+
continue
108+
}
109+
// check in blacklist if the ts.Name struct is blacklisted
110+
if key := fmt.Sprintf("%v", ts.Name); blacklistStruct[key] {
111+
logf("Struct %v blacklisted; skipping.", key)
112+
continue
113+
}
110114
st, ok := ts.Type.(*ast.StructType)
111115
if !ok {
112116
continue
@@ -118,14 +122,9 @@ func (t *templateData) processAST(f *ast.File) error {
118122
}
119123

120124
fieldName := field.Names[0]
121-
// check in blacklist if the ts.Name struct is blacklisted
122-
if key := fmt.Sprintf("%v", ts.Name); blacklistStruct[key] {
123-
logf("Struct %v blacklisted; skipping.", key)
124-
continue
125-
}
126-
// check in blacklist if the field is blacklisted
127-
if key := fmt.Sprintf("%v", fieldName); blacklistField[key] {
128-
logf("Field %v is blacklisted; skipping.", key)
125+
// skip unexported identifiers
126+
if !fieldName.IsExported() {
127+
logf("Field %v is unexported; skipping.", fieldName)
129128
continue
130129
}
131130
// check for "struct.method" in blacklist

github/github-accessors.go

Lines changed: 0 additions & 184 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)