MCPcopy Create free account
hub / github.com/cli/cli / New

Function New

internal/codespaces/api/api.go:72–104  ·  view source on GitHub ↗

New creates a new API client connecting to the configured endpoints with the HTTP client.

(f *cmdutil.Factory)

Source from the content-addressed store, hash-verified

70
71// New creates a new API client connecting to the configured endpoints with the HTTP client.
72func New(f *cmdutil.Factory) *API {
73 apiURL := os.Getenv("GITHUB_API_URL")
74 if apiURL == "" {
75 cfg, err := f.Config()
76 if err != nil {
77 // fallback to the default api endpoint
78 apiURL = defaultAPIURL
79 } else {
80 host, _ := cfg.Authentication().DefaultHost()
81 apiURL = ghinstance.RESTPrefix(host)
82 }
83 }
84
85 serverURL := os.Getenv("GITHUB_SERVER_URL")
86 if serverURL == "" {
87 cfg, err := f.Config()
88 if err != nil {
89 // fallback to the default server endpoint
90 serverURL = defaultServerURL
91 } else {
92 host, _ := cfg.Authentication().DefaultHost()
93 serverURL = ghinstance.HostPrefix(host)
94 }
95 }
96
97 return &API{
98 client: f.HttpClient,
99 externalClient: f.ExternalHttpClient,
100 githubAPI: strings.TrimSuffix(apiURL, "/"),
101 githubServer: strings.TrimSuffix(serverURL, "/"),
102 retryBackoff: 100 * time.Millisecond,
103 }
104}
105
106// User represents a GitHub user.
107type User struct {

Calls 5

RESTPrefixFunction · 0.92
HostPrefixFunction · 0.92
ConfigMethod · 0.65
DefaultHostMethod · 0.65
AuthenticationMethod · 0.65