Skip to content

Improve base URL configuration #5

@jmcampanini

Description

@jmcampanini

// originally suggested by @bluekeyes

Currently, users have to specify the base URL three times in configuration:

  1. The web URL, used for the OAuth login flow
  2. The v3 API URL
  3. The v4 API URL

It seems like we should be able to compute all of these given a single base URL, as long as we assume that github.com works in a known consistent way (most other client libraries seem to assume this.) Something like:

  • If if the base URL host is github.com, use api.github.com and api.github.com/graphql
  • Otherwise, assume an enterprise installation and use baseURL/api/v3 and baseURL/api/v4/graphql

The place where this would break is if someone is running a named proxy for github.com (i.e. not using the native proxy support in http.Client) or if someone put a proxy in front of their enterprise install to mess with the URLs. I don't think it's worth support either of those cases.

Maybe something like this:

type URLs struct {
  Web   *url.URL
  APIv3 *url.URL
  APIv4 *url.URL
}

func NewURLs(baseURL string) (*URLs, error) {
  // parse baseURL, set others based on if it contains github.com or not
}

Then ClientCreator could take one of these objects and BaseHandler could expose one for use in other places if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions