UpdatePorts atomically adds and removes forwarded HTTP ports on an instance.
(instanceID string, addPorts, removePorts []int)
| 286 | |
| 287 | // UpdatePorts atomically adds and removes forwarded HTTP ports on an instance. |
| 288 | func (c *Client) UpdatePorts(instanceID string, addPorts, removePorts []int) (*PortAddResponse, error) { |
| 289 | if len(addPorts) == 0 && len(removePorts) == 0 { |
| 290 | return nil, fmt.Errorf("no ports specified") |
| 291 | } |
| 292 | var resp PortAddResponse |
| 293 | err := c.doRequest(context.Background(), "PATCH", fmt.Sprintf("/v1/instances/%s/ports", instanceID), PortUpdateRequest{ |
| 294 | AddPorts: addPorts, |
| 295 | RemovePorts: removePorts, |
| 296 | }, &resp) |
| 297 | if err != nil { |
| 298 | var apiErr *APIError |
| 299 | if errors.As(err, &apiErr) && apiErr.StatusCode == 404 { |
| 300 | return nil, fmt.Errorf("instance not found") |
| 301 | } |
| 302 | return nil, err |
| 303 | } |
| 304 | return &resp, nil |
| 305 | } |
| 306 | |
| 307 | // RemovePorts removes one or more forwarded HTTP ports from an instance in a single call. |
| 308 | func (c *Client) RemovePorts(instanceID string, ports []int) error { |
no test coverage detected