From fcf4b18ac8a7b0606490aec2f47de9e3edcc28dd Mon Sep 17 00:00:00 2001 From: Zhiwei Liang <121905282+zliang-akamai@users.noreply.github.com> Date: Wed, 15 Jan 2025 14:25:07 -0500 Subject: [PATCH] rfc: doPOSTRequestNoResponseBody (#654) Co-authored-by: Ye Chen <127243817+yec-akamai@users.noreply.github.com> --- instances.go | 6 ++---- request_helpers.go | 12 ++++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/instances.go b/instances.go index 6903fa766..bdbbc4831 100644 --- a/instances.go +++ b/instances.go @@ -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 diff --git a/request_helpers.go b/request_helpers.go index 152a26433..28ed21499 100644 --- a/request_helpers.go +++ b/request_helpers.go @@ -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](