Documentation
¶
Index ¶
- Constants
- Variables
- func GetNewOpts(opts *github.SearchOptions, resp *github.Response) *github.SearchOptions
- func NewClient(authenticated *http.Client, gccf ...ClientCreationFunc) (*github.Client, error)
- func NewClientDefault(authenticated *http.Client) (*github.Client, error)
- type ClientCreationFunc
- type Queryable
Constants ¶
const (
// PerPageResultsDefault defines the default page size for search query responses
PerPageResultsDefault = 100
)
Variables ¶
var ( // WellKnownTokenVarNames lists known env var names for Github related tokens WellKnownTokenVarNames = []string{"GITHUB_TOKEN", "GH_TOKEN", "NPM_TOKEN"} )
Functions ¶
func GetNewOpts ¶
func GetNewOpts(opts *github.SearchOptions, resp *github.Response) *github.SearchOptions
GetNewOpts provides github.SearchOptions optionally based on existing search options and an API response.
This facilitates setting proper search options for handling paging, properly, and can be used in a do-while loop that encapsulates and accumulates API responses.
allRepos := []*github.Repository{}
for opts = GetNewOpts(opts, nil); opts != nil; opts = GetNewOpts(opts, resp) {
res, resp, err = gh.Search.Repositories(ctx, query, opts)
if err != nil {
return nil, err
}
allRepos = append(allRepos, res.Repositories...)
}
When opts and resp are provided, GetNewOpts will return nil if there is no page left to query.
func NewClient ¶
NewClient conveniently creates a client connection to the Github API based on an already authenticated http client connection
If the authenticated client is not provided, a new client will be created by calling [NewOAuthClient] trying to find tokens in [WellKnownGithubTokenVarNames]
Providing a parameter for gccf would allow creating the github client with a customized function
Types ¶
type ClientCreationFunc ¶
ClientCreationFunc defines the structure of a function, which is capable for creating an oauth2 client