Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: doPOSTRequestNoResponseBody Request Helper that doesn't Expecets Return Value #654

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading