Skip to content

Commit

Permalink
gen-accessors: fix list of blacklisted structs and fields
Browse files Browse the repository at this point in the history
- Remove "service" from list of blacklisted fields because that was a
  mistake in the previous commit.
- Add "service" to list of blacklisted structs because it  would make
  more sense to not generate accessors for its fields.
- Remove all debug printf statements.
  • Loading branch information
sahildua2305 committed Nov 23, 2017
1 parent 6b2553c commit 60c9a1e
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions github/gen-accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,27 @@ var (

sourceTmpl = template.Must(template.New("source").Parse(source))

// blacklist lists which "struct.method" combos to not generate.
blacklist = map[string]bool{
// this blacklist lists structs for which we don't want to generate
// accessors.
blacklistStructMethod = map[string]bool{
"RepositoryContent.GetContent": true,
"Client.GetBaseURL": true,
"Client.GetUploadURL": true,
"ErrorResponse.GetResponse": true,
"RateLimitError.GetResponse": true,
"AbuseRateLimitError.GetResponse": true,
}
// this blacklist lists structs for which we don't want to generate
// accessors.
blacklistStruct = map[string]bool{
"Client": true,
"service": true,
}
// this blacklist lists fields for which we don't want to generate
// accessors.
blacklistField = map[string]bool{
"client": true,
}
)

func logf(fmt string, args ...interface{}) {
Expand Down Expand Up @@ -106,7 +118,18 @@ func (t *templateData) processAST(f *ast.File) error {
}

fieldName := field.Names[0]
if key := fmt.Sprintf("%v.Get%v", ts.Name, fieldName); blacklist[key] {
// check in blacklist if the ts.Name struct is blacklisted
if key := fmt.Sprintf("%v", ts.Name); blacklistStruct[key] {
logf("Struct %v blacklisted; skipping.", key)
continue
}
// check in blacklist if the field is blacklisted
if key := fmt.Sprintf("%v", fieldName); blacklistField[key] {
logf("Field %v is blacklisted; skipping.", key)
continue
}
// check for "struct.method" in blacklist
if key := fmt.Sprintf("%v.Get%v", ts.Name, fieldName); blacklistStructMethod[key] {
logf("Method %v blacklisted; skipping.", key)
continue
}
Expand Down

0 comments on commit 60c9a1e

Please sign in to comment.