| 191 | } |
| 192 | |
| 193 | func New(options ...Option) (Client, error) { |
| 194 | cfg := &config{ |
| 195 | requestTimeout: api.DefaultClientRequestTimeout, |
| 196 | responseTimeout: api.DefaultClientResponseHeaderTimeout, |
| 197 | } |
| 198 | for _, opt := range options { |
| 199 | if err := opt(cfg); err != nil { |
| 200 | return nil, err |
| 201 | } |
| 202 | } |
| 203 | if cfg.dialContext == nil { |
| 204 | cfg.dialContext = dialFromPath(api.DaemonSocketPath()) |
| 205 | } |
| 206 | c := &http.Client{ |
| 207 | Transport: &http.Transport{ |
| 208 | // re-use the same connection to the runtime, this speeds up subsequent |
| 209 | // calls. |
| 210 | MaxConnsPerHost: api.DefaultClientMaxConnsPerHost, |
| 211 | MaxIdleConnsPerHost: api.DefaultClientMaxIdleConnsPerHost, |
| 212 | // keep the connection alive (good for long-lived clients) |
| 213 | IdleConnTimeout: api.DefaultClientIdleConnTimeout, |
| 214 | // By default it is 1 second, but can be overridden with [WithResponseTimeout] |
| 215 | ResponseHeaderTimeout: cfg.responseTimeout, |
| 216 | TLSHandshakeTimeout: api.DefaultClientTLSHandshakeTimeout, |
| 217 | |
| 218 | DialContext: cfg.dialContext, |
| 219 | DisableKeepAlives: false, |
| 220 | DisableCompression: false, |
| 221 | ForceAttemptHTTP2: true, |
| 222 | }, |
| 223 | // by default Timeout will be 0 (meaning no timeout) |
| 224 | // it can be overwritten with [WithTimeout] |
| 225 | Timeout: cfg.requestTimeout, |
| 226 | } |
| 227 | return &client{ |
| 228 | resolverClient: resolver.NewResolverClient(c), |
| 229 | engineClient: pluginsv1connect.NewPluginManagementServiceClient(c, "http://unix"), |
| 230 | versionClient: healthv1connect.NewVersionServiceClient(c, "http://unix"), |
| 231 | }, nil |
| 232 | } |
| 233 | |
| 234 | func (c client) ListPlugins(ctx context.Context) ([]PluginInfo, error) { |
| 235 | req := connect.NewRequest(pluginsv1.ListPluginsRequest_builder{}.Build()) |