google/go-github

Refactor codebase to use value parameters instead of pointers where appropriate

オープン

#3,644 opened on 2025/07/24

 (24 件のコメント) (4 件のリアクション) (3 人の担当者)Go (1,399 件のフォーク)batch import
Breaking API Changeenhancementgood first issue

Repository metrics

Stars
 (6,822 個のスター)
PR merge metrics
 (PR metrics pending)

説明

Many methods in the codebase, such as:


func (s *RepositoriesService) CreateRelease(ctx context.Context, owner, repo string, release *RepositoryRelease) (*RepositoryRelease, *Response, error)

use pointer parameters (e.g. *RepositoryRelease) even when the function doesn't mutate the input. This appears to be a result of convention or copy-paste, not a performance-driven choice.

For instance, in CreateRelease, the RepositoryRelease struct is relatively large (~15+ fields), but most of its fields are pointers themselves. As such, passing it by value would have negligible performance impact in typical API usage. Moreover, value semantics would improve clarity, especially for required arguments that aren't modified.

To improve API design consistency and safety, we should:

  • Audit method signatures that accept pointer structs as input

  • Change them to accept values when:

    • The input is required (not optional)

    • The function does not modify the input

  • Optionally introduce dedicated input structs for specific operations (e.g. CreateRepositoryRelease with only the fields needed for creation)

Note: This would be a breaking change and should be handled carefully, possibly across multiple PRs.

Originally posted by @gmlewis in https://github.com/google/go-github/pull/3636#discussion_r2228429223

コントリビューターガイド