Go-github: github-accessors.go: Missing accessors for non-Struct type fields

Created on 9 Nov 2017  路  5Comments  路  Source: google/go-github

While working on #770, I noticed that we are creating accessors only for fields which have a struct type. I looked further into it today and confirmed the same. Is this intentional? If so, why?
/cc @gmlewis @shurcooL

Most helpful comment

The type of that particular field CurrentUserOrganizationURLs is []string. It鈥檚 not a pointer.

Not having an accessor for it seems reasonable, since the accessors exist for pointer fields to help prevent nil pointer dereference panics when a field is missing. Since there鈥檚 no pointer here, there鈥檚 nothing to protect against. The following code can never panic:

fmt.Println(len(feeds.CurrentUserOrganizationURLs))

Does that make sense? Or am I missing something? What would having an accessor for that field accomplish?

All 5 comments

I'm not sure I understand what you mean.
https://github.com/google/go-github/blob/master/github/github-accessors.go#L24
returns a string, for example.

@sahildua2305 Can you give some examples of fields that are missing accessors?

The type of that particular field CurrentUserOrganizationURLs is []string. It鈥檚 not a pointer.

Not having an accessor for it seems reasonable, since the accessors exist for pointer fields to help prevent nil pointer dereference panics when a field is missing. Since there鈥檚 no pointer here, there鈥檚 nothing to protect against. The following code can never panic:

fmt.Println(len(feeds.CurrentUserOrganizationURLs))

Does that make sense? Or am I missing something? What would having an accessor for that field accomplish?

Oh right! Makes sense. I knew I was missing something. Thanks for clearing it out. 馃挴

Was this page helpful?
0 / 5 - 0 ratings

Related issues

csandanov picture csandanov  路  3Comments

gmlewis picture gmlewis  路  3Comments

smola picture smola  路  3Comments

gmlewis picture gmlewis  路  3Comments

OGKevin picture OGKevin  路  3Comments