MCPcopy Create free account
hub / github.com/compozy/agh / NewClient

Function NewClient

internal/registry/github/client.go:100–146  ·  view source on GitHub ↗

NewClient constructs a GitHub Releases registry client.

(baseURL string, opts ...Option)

Source from the content-addressed store, hash-verified

98
99// NewClient constructs a GitHub Releases registry client.
100func NewClient(baseURL string, opts ...Option) *Client {
101 client := &Client{
102 baseURL: strings.TrimSpace(baseURL),
103 httpClient: &http.Client{Timeout: defaultRequestTimeout},
104 sleep: sleepContext,
105 initialBackoff: defaultInitialBackoff,
106 maxBackoff: defaultMaxBackoff,
107 maxRetries: defaultMaxRetries,
108 logger: slog.Default(),
109 token: strings.TrimSpace(os.Getenv("GITHUB_TOKEN")),
110 }
111 if client.baseURL == "" {
112 client.baseURL = defaultBaseURL
113 }
114
115 for _, opt := range opts {
116 if opt != nil {
117 opt(client)
118 }
119 }
120
121 if strings.TrimSpace(client.baseURL) == "" {
122 client.baseURL = defaultBaseURL
123 }
124 client.baseURL = strings.TrimRight(client.baseURL, "/")
125
126 if client.httpClient == nil {
127 client.httpClient = &http.Client{Timeout: defaultRequestTimeout}
128 }
129 if client.sleep == nil {
130 client.sleep = sleepContext
131 }
132 if client.initialBackoff <= 0 {
133 client.initialBackoff = defaultInitialBackoff
134 }
135 if client.maxBackoff <= 0 {
136 client.maxBackoff = defaultMaxBackoff
137 }
138 if client.maxRetries < 0 {
139 client.maxRetries = 0
140 }
141 if client.logger == nil {
142 client.logger = slog.Default()
143 }
144
145 return client
146}
147
148// WithHTTPClient overrides the underlying HTTP client.
149func WithHTTPClient(httpClient *http.Client) Option {

Calls

no outgoing calls