Browse Source

Avoid unnecessary FooService allocations

Fixes #389
Fixes #390
Matthew Dempsky 10 years ago
committed by Will Norris
parent
commit
8808be6605
15 changed files with 35 additions and 56 deletions
  1. +1
    -3
      github/activity.go
  2. +1
    -3
      github/authorizations.go
  3. +1
    -3
      github/gists.go
  4. +1
    -3
      github/git.go
  5. +21
    -14
      github/github.go
  6. +1
    -3
      github/gitignore.go
  7. +1
    -3
      github/issues.go
  8. +1
    -3
      github/licenses.go
  9. +1
    -3
      github/migrations.go
  10. +1
    -3
      github/orgs.go
  11. +1
    -3
      github/pulls.go
  12. +1
    -3
      github/reactions.go
  13. +1
    -3
      github/repos.go
  14. +1
    -3
      github/search.go
  15. +1
    -3
      github/users.go

+ 1
- 3
github/activity.go View File

@ -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 {


+ 1
- 3
github/authorizations.go View File

@ -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 {


+ 1
- 3
github/gists.go View File

@ -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 {


+ 1
- 3
github/git.go View File

@ -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

+ 21
- 14
github/github.go View File

@ -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
}


+ 1
- 3
github/gitignore.go View File

@ -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 {


+ 1
- 3
github/issues.go View File

@ -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 {


+ 1
- 3
github/licenses.go View File

@ -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 {


+ 1
- 3
github/migrations.go View File

@ -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 {


+ 1
- 3
github/orgs.go View File

@ -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 {


+ 1
- 3
github/pulls.go View File

@ -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 {


+ 1
- 3
github/reactions.go View File

@ -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 {


+ 1
- 3
github/repos.go View File

@ -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 {


+ 1
- 3
github/search.go View File

@ -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 {


+ 1
- 3
github/users.go View File

@ -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 {


Loading…
Cancel
Save