diff --git a/github/activity.go b/github/activity.go index 88ad8d2..d719ebb 100644 --- a/github/activity.go +++ b/github/activity.go @@ -9,9 +9,7 @@ package github // methods of the GitHub API. // // GitHub API docs: http://developer.github.com/v3/activity/ -type ActivityService struct { - client *Client -} +type ActivityService service // FeedLink represents a link to a related resource. type FeedLink struct { diff --git a/github/authorizations.go b/github/authorizations.go index 2839f93..b295d49 100644 --- a/github/authorizations.go +++ b/github/authorizations.go @@ -47,9 +47,7 @@ const ( // an OAuth token. // // GitHub API docs: https://developer.github.com/v3/oauth_authorizations/ -type AuthorizationsService struct { - client *Client -} +type AuthorizationsService service // Authorization represents an individual GitHub authorization. type Authorization struct { diff --git a/github/gists.go b/github/gists.go index b452bcb..697fcb5 100644 --- a/github/gists.go +++ b/github/gists.go @@ -14,9 +14,7 @@ import ( // methods of the GitHub API. // // GitHub API docs: http://developer.github.com/v3/gists/ -type GistsService struct { - client *Client -} +type GistsService service // Gist represents a GitHub's gist. type Gist struct { diff --git a/github/git.go b/github/git.go index a80e55b..c934751 100644 --- a/github/git.go +++ b/github/git.go @@ -9,6 +9,4 @@ package github // methods of the GitHub API. // // GitHub API docs: http://developer.github.com/v3/git/ -type GitService struct { - client *Client -} +type GitService service diff --git a/github/github.go b/github/github.go index 5a4afcf..49bb74b 100644 --- a/github/github.go +++ b/github/github.go @@ -108,6 +108,8 @@ type Client struct { rateLimits [categories]Rate // Rate limits for the client as determined by the most recent API calls. mostRecent rateLimitCategory + common service // Reuse a single struct instead of allocating one for each service on the heap. + // Services used for talking to different parts of the GitHub API. Activity *ActivityService Authorizations *AuthorizationsService @@ -125,6 +127,10 @@ type Client struct { Reactions *ReactionsService } +type service struct { + client *Client +} + // ListOptions specifies the optional parameters to various List methods that // support pagination. type ListOptions struct { @@ -174,20 +180,21 @@ func NewClient(httpClient *http.Client) *Client { uploadURL, _ := url.Parse(uploadBaseURL) c := &Client{client: httpClient, BaseURL: baseURL, UserAgent: userAgent, UploadURL: uploadURL} - c.Activity = &ActivityService{client: c} - c.Authorizations = &AuthorizationsService{client: c} - c.Gists = &GistsService{client: c} - c.Git = &GitService{client: c} - c.Gitignores = &GitignoresService{client: c} - c.Issues = &IssuesService{client: c} - c.Organizations = &OrganizationsService{client: c} - c.PullRequests = &PullRequestsService{client: c} - c.Repositories = &RepositoriesService{client: c} - c.Search = &SearchService{client: c} - c.Users = &UsersService{client: c} - c.Licenses = &LicensesService{client: c} - c.Migrations = &MigrationService{client: c} - c.Reactions = &ReactionsService{client: c} + c.common.client = c + c.Activity = (*ActivityService)(&c.common) + c.Authorizations = (*AuthorizationsService)(&c.common) + c.Gists = (*GistsService)(&c.common) + c.Git = (*GitService)(&c.common) + c.Gitignores = (*GitignoresService)(&c.common) + c.Issues = (*IssuesService)(&c.common) + c.Licenses = (*LicensesService)(&c.common) + c.Migrations = (*MigrationService)(&c.common) + c.Organizations = (*OrganizationsService)(&c.common) + c.PullRequests = (*PullRequestsService)(&c.common) + c.Reactions = (*ReactionsService)(&c.common) + c.Repositories = (*RepositoriesService)(&c.common) + c.Search = (*SearchService)(&c.common) + c.Users = (*UsersService)(&c.common) return c } diff --git a/github/gitignore.go b/github/gitignore.go index 31d5902..faaceb5 100644 --- a/github/gitignore.go +++ b/github/gitignore.go @@ -11,9 +11,7 @@ import "fmt" // GitHub API. // // GitHub API docs: http://developer.github.com/v3/gitignore/ -type GitignoresService struct { - client *Client -} +type GitignoresService service // Gitignore represents a .gitignore file as returned by the GitHub API. type Gitignore struct { diff --git a/github/issues.go b/github/issues.go index 5d6408d..3957f22 100644 --- a/github/issues.go +++ b/github/issues.go @@ -14,9 +14,7 @@ import ( // methods of the GitHub API. // // GitHub API docs: http://developer.github.com/v3/issues/ -type IssuesService struct { - client *Client -} +type IssuesService service // Issue represents a GitHub issue on a repository. type Issue struct { diff --git a/github/licenses.go b/github/licenses.go index 93f6932..35cd234 100644 --- a/github/licenses.go +++ b/github/licenses.go @@ -11,9 +11,7 @@ import "fmt" // methods of the GitHub API. // // GitHub API docs: http://developer.github.com/v3/pulls/ -type LicensesService struct { - client *Client -} +type LicensesService service // License represents an open source license. type License struct { diff --git a/github/migrations.go b/github/migrations.go index 8a7bc5f..a7890b0 100644 --- a/github/migrations.go +++ b/github/migrations.go @@ -16,9 +16,7 @@ import ( // in the GitHub API. // // GitHub API docs: https://developer.github.com/v3/migration/ -type MigrationService struct { - client *Client -} +type MigrationService service // Migration represents a GitHub migration (archival). type Migration struct { diff --git a/github/orgs.go b/github/orgs.go index c71be22..e71055c 100644 --- a/github/orgs.go +++ b/github/orgs.go @@ -14,9 +14,7 @@ import ( // in the GitHub API. // // GitHub API docs: http://developer.github.com/v3/orgs/ -type OrganizationsService struct { - client *Client -} +type OrganizationsService service // Organization represents a GitHub organization account. type Organization struct { diff --git a/github/pulls.go b/github/pulls.go index 535ee46..fe3dc3b 100644 --- a/github/pulls.go +++ b/github/pulls.go @@ -14,9 +14,7 @@ import ( // methods of the GitHub API. // // GitHub API docs: http://developer.github.com/v3/pulls/ -type PullRequestsService struct { - client *Client -} +type PullRequestsService service // PullRequest represents a GitHub pull request on a repository. type PullRequest struct { diff --git a/github/reactions.go b/github/reactions.go index 68a16af..03b131b 100644 --- a/github/reactions.go +++ b/github/reactions.go @@ -11,9 +11,7 @@ import "fmt" // GitHub API. // // GitHub API docs: https://developer.github.com/v3/reactions/ -type ReactionsService struct { - client *Client -} +type ReactionsService service // Reaction represents a GitHub reaction. type Reaction struct { diff --git a/github/repos.go b/github/repos.go index ffefce9..fb402ee 100644 --- a/github/repos.go +++ b/github/repos.go @@ -11,9 +11,7 @@ import "fmt" // methods of the GitHub API. // // GitHub API docs: http://developer.github.com/v3/repos/ -type RepositoriesService struct { - client *Client -} +type RepositoriesService service // Repository represents a GitHub repository. type Repository struct { diff --git a/github/search.go b/github/search.go index 073b6c0..0c7ffcb 100644 --- a/github/search.go +++ b/github/search.go @@ -15,9 +15,7 @@ import ( // in the GitHub API. // // GitHub API docs: http://developer.github.com/v3/search/ -type SearchService struct { - client *Client -} +type SearchService service // SearchOptions specifies optional parameters to the SearchService methods. type SearchOptions struct { diff --git a/github/users.go b/github/users.go index 1720804..8f63746 100644 --- a/github/users.go +++ b/github/users.go @@ -11,9 +11,7 @@ import "fmt" // methods of the GitHub API. // // GitHub API docs: http://developer.github.com/v3/users/ -type UsersService struct { - client *Client -} +type UsersService service // User represents a GitHub user. type User struct {