Skip to content

Commit

Permalink
rfc: doPOSTRequestNoResponseBody (#654)
Browse files Browse the repository at this point in the history
Co-authored-by: Ye Chen <127243817+yec-akamai@users.noreply.github.com>
  • Loading branch information
zliang-akamai and yec-akamai authored Jan 15, 2025
1 parent 9193012 commit fcf4b18
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 2 additions & 4 deletions instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,15 +487,13 @@ type InstanceUpgradeOptions struct {
// UpgradeInstance upgrades a Linode to its next generation.
func (c *Client) UpgradeInstance(ctx context.Context, linodeID int, opts InstanceUpgradeOptions) error {
e := formatAPIPath("linode/instances/%d/mutate", linodeID)
_, err := doPOSTRequest[Instance](ctx, c, e, opts)
return err
return doPOSTRequestNoResponseBody(ctx, c, e, opts)
}

// MigrateInstance - Migrate an instance
func (c *Client) MigrateInstance(ctx context.Context, linodeID int, opts InstanceMigrateOptions) error {
e := formatAPIPath("linode/instances/%d/migrate", linodeID)
_, err := doPOSTRequest[Instance](ctx, c, e, opts)
return err
return doPOSTRequestNoResponseBody(ctx, c, e, opts)
}

// simpleInstanceAction is a helper for Instance actions that take no parameters
Expand Down
12 changes: 12 additions & 0 deletions request_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ func doPOSTRequest[T, O any](
return r.Result().(*T), nil
}

// doPOSTRequest runs a POST request using the given client, API endpoint,
// and options/body. It expects only empty response from the endpoint.
func doPOSTRequestNoResponseBody[T any](
ctx context.Context,
client *Client,
endpoint string,
options ...T,
) error {
_, err := doPOSTRequest[any, T](ctx, client, endpoint, options...)
return err
}

// doPUTRequest runs a PUT request using the given client, API endpoint,
// and options/body.
func doPUTRequest[T, O any](
Expand Down

0 comments on commit fcf4b18

Please sign in to comment.