MCPcopy Index your code
hub / github.com/cli/cli / New

Function New

internal/codespaces/api/api.go:71–103  ·  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

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

Calls 5

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