Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,16 @@ recommended when making requests using short-lived credentials such as a

### Creating and Updating Resources ###

All structs for GitHub resources use pointer values for all non-repeated fields.
This allows distinguishing between unset fields and those set to a zero-value.
Many resource and request structs use pointers for optional scalar fields. This
allows distinguishing between unset fields and those set to a zero-value.
Required fields such as `CreateRepositoryRequest.Name` use value types.
Use the `new` builtin to easily create these pointers for string,
bool, and int values. For example:

```go
// create a new private repository named "foo"
repo := &github.Repository{
Name: new("foo"),
repo := github.CreateRepositoryRequest{
Name: "foo",
Private: new(true),
}
client.Repositories.Create(ctx, "", repo)
Expand Down
2 changes: 1 addition & 1 deletion example/newrepo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func main() {
log.Fatal(err)
}

r := &github.Repository{Name: name, Private: private, Description: description, AutoInit: autoInit}
r := github.CreateRepositoryRequest{Name: *name, Private: private, Description: description, AutoInit: autoInit}
repo, _, err := client.Repositories.Create(ctx, "", r)
if err != nil {
log.Fatal(err)
Expand Down
9 changes: 5 additions & 4 deletions github/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,15 @@ https://docs.github.com/rest/using-the-rest-api/best-practices-for-using-the-res

# Creating and Updating Resources

All structs for GitHub resources use pointer values for all non-repeated fields.
This allows distinguishing between unset fields and those set to a zero-value.
Many resource and request structs use pointers for optional scalar fields. This
allows distinguishing between unset fields and those set to a zero-value.
Required fields such as [CreateRepositoryRequest.Name] use value types.
Use the new builtin to easily create these pointers for string,
bool, and int values. For example:

// create a new private repository named "foo"
repo := &github.Repository{
Name: new("foo"),
repo := github.CreateRepositoryRequest{
Name: "foo",
Private: new(true),
}
client.Repositories.Create(ctx, "", repo)
Expand Down
216 changes: 216 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading