From bb6e5765703ecd9142583b63946ffd215d103d64 Mon Sep 17 00:00:00 2001 From: Tinyblargon <76069640+Tinyblargon@users.noreply.github.com> Date: Thu, 29 Feb 2024 21:35:11 +0100 Subject: [PATCH] refactor: inline errors --- proxmox/snapshot.go | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/proxmox/snapshot.go b/proxmox/snapshot.go index 704ed02d..e78ea87c 100644 --- a/proxmox/snapshot.go +++ b/proxmox/snapshot.go @@ -25,12 +25,10 @@ func (config ConfigSnapshot) mapToApiValues() map[string]interface{} { // Creates a snapshot and validates the input func (config ConfigSnapshot) Create(c *Client, vmr *VmRef) (err error) { - err = c.CheckVmRef(vmr) - if err != nil { + if err = c.CheckVmRef(vmr); err != nil { return } - err = config.Validate() - if err != nil { + if err = config.Validate(); err != nil { return } return config.Create_Unsafe(c, vmr) @@ -59,8 +57,7 @@ func (config ConfigSnapshot) Validate() error { type rawSnapshots []interface{} func ListSnapshots(c *Client, vmr *VmRef) (rawSnapshots, error) { - err := c.CheckVmRef(vmr) - if err != nil { + if err := c.CheckVmRef(vmr); err != nil { return nil, err } return c.GetItemConfigInterfaceArray("/nodes/"+vmr.node+"/"+vmr.vmType+"/"+strconv.Itoa(vmr.vmId)+"/snapshot/", "Guest", "SNAPSHOTS") @@ -150,12 +147,10 @@ const ( // Deletes the specified snapshot, validates the input func (snap SnapshotName) Delete(c *Client, vmr *VmRef) (exitStatus string, err error) { - err = c.CheckVmRef(vmr) - if err != nil { + if err = c.CheckVmRef(vmr); err != nil { return } - err = snap.Validate() - if err != nil { + if err = snap.Validate(); err != nil { return } // TODO check if snapshot exists @@ -169,8 +164,7 @@ func (snap SnapshotName) Delete_Unsafe(c *Client, vmr *VmRef) (exitStatus string // Rollback to the specified snapshot, validates the input func (snap SnapshotName) Rollback(c *Client, vmr *VmRef) (exitStatus string, err error) { - err = c.CheckVmRef(vmr) - if err != nil { + if err = c.CheckVmRef(vmr); err != nil { return } if err = snap.Validate(); err != nil { @@ -187,12 +181,10 @@ func (snap SnapshotName) Rollback_Unsafe(c *Client, vmr *VmRef) (exitStatus stri // Updates the description of the specified snapshot, validates the input func (snap SnapshotName) UpdateDescription(c *Client, vmr *VmRef, description string) (err error) { - err = c.CheckVmRef(vmr) - if err != nil { + if err = c.CheckVmRef(vmr); err != nil { return } - err = snap.Validate() - if err != nil { + if err = snap.Validate(); err != nil { return } // TODO check if snapshot exists