Skip to content

Commit fcf4b18

Browse files
rfc: doPOSTRequestNoResponseBody (#654)
Co-authored-by: Ye Chen <[email protected]>
1 parent 9193012 commit fcf4b18

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

instances.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,15 +487,13 @@ type InstanceUpgradeOptions struct {
487487
// UpgradeInstance upgrades a Linode to its next generation.
488488
func (c *Client) UpgradeInstance(ctx context.Context, linodeID int, opts InstanceUpgradeOptions) error {
489489
e := formatAPIPath("linode/instances/%d/mutate", linodeID)
490-
_, err := doPOSTRequest[Instance](ctx, c, e, opts)
491-
return err
490+
return doPOSTRequestNoResponseBody(ctx, c, e, opts)
492491
}
493492

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

501499
// simpleInstanceAction is a helper for Instance actions that take no parameters

request_helpers.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ func doPOSTRequest[T, O any](
149149
return r.Result().(*T), nil
150150
}
151151

152+
// doPOSTRequest runs a POST request using the given client, API endpoint,
153+
// and options/body. It expects only empty response from the endpoint.
154+
func doPOSTRequestNoResponseBody[T any](
155+
ctx context.Context,
156+
client *Client,
157+
endpoint string,
158+
options ...T,
159+
) error {
160+
_, err := doPOSTRequest[any, T](ctx, client, endpoint, options...)
161+
return err
162+
}
163+
152164
// doPUTRequest runs a PUT request using the given client, API endpoint,
153165
// and options/body.
154166
func doPUTRequest[T, O any](

0 commit comments

Comments
 (0)