diff --git a/proxmox/config_pool.go b/proxmox/config_pool.go index ae0ff51c..fb85346c 100644 --- a/proxmox/config_pool.go +++ b/proxmox/config_pool.go @@ -4,6 +4,8 @@ import ( "errors" "regexp" "strconv" + + "github.com/Telmate/proxmox-api-go/internal/util" ) func ListPools(c *Client) ([]PoolName, error) { @@ -69,8 +71,7 @@ func (ConfigPool) mapToSDK(params map[string]interface{}) (config ConfigPool) { config.Name = PoolName(v.(string)) } if v, isSet := params["comment"]; isSet { - tmp := v.(string) - config.Comment = &tmp + config.Comment = util.Pointer(v.(string)) } if v, isSet := params["members"]; isSet { guests := make([]uint, 0) diff --git a/proxmox/config_qemu.go b/proxmox/config_qemu.go index e997f8cd..4816a1b7 100644 --- a/proxmox/config_qemu.go +++ b/proxmox/config_qemu.go @@ -406,7 +406,7 @@ func (ConfigQemu) mapToStruct(vmr *VmRef, params map[string]interface{}) (*Confi id := rxDeviceID.FindStringSubmatch(unusedDiskName) diskID, err := strconv.Atoi(id[0]) if err != nil { - return nil, fmt.Errorf(fmt.Sprintf("Unable to parse unused disk id from input string '%v' tried to convert '%v' to integer.", unusedDiskName, diskID)) + return nil, fmt.Errorf("unable to parse unused disk id from input string '%v' tried to convert '%v' to integer", unusedDiskName, diskID) } finalDiskConfMap["slot"] = diskID @@ -1407,7 +1407,7 @@ const ( func (id QemuNetworkInterfaceID) Validate() error { if id > 31 { - return fmt.Errorf(QemuNetworkInterfaceID_Error_Invalid) + return errors.New(QemuNetworkInterfaceID_Error_Invalid) } return nil } diff --git a/proxmox/config_qemu_cloudinit.go b/proxmox/config_qemu_cloudinit.go index 7e2dee45..aaf1b7ee 100644 --- a/proxmox/config_qemu_cloudinit.go +++ b/proxmox/config_qemu_cloudinit.go @@ -9,6 +9,8 @@ import ( "regexp" "strconv" "strings" + + "github.com/Telmate/proxmox-api-go/internal/util" ) var regexMultipleNewlineEncoded = regexp.MustCompile(`(%0A)+`) @@ -140,13 +142,11 @@ func (CloudInit) mapToSDK(params map[string]interface{}) *CloudInit { set = true } if v, isSet := params["cipassword"]; isSet { - tmp := v.(string) - ci.UserPassword = &tmp + ci.UserPassword = util.Pointer(v.(string)) set = true } if v, isSet := params["ciupgrade"]; isSet { - tmp := Itob(int(v.(float64))) - ci.UpgradePackages = &tmp + ci.UpgradePackages = util.Pointer(Itob(int(v.(float64)))) set = true } if v, isSet := params["ciuser"]; isSet { @@ -157,8 +157,7 @@ func (CloudInit) mapToSDK(params map[string]interface{}) *CloudInit { } } if v, isSet := params["sshkeys"]; isSet { - tmp := sshKeyUrlDecode(v.(string)) - ci.PublicSSHkeys = &tmp + ci.PublicSSHkeys = util.Pointer(sshKeyUrlDecode(v.(string))) set = true } var dnsSet bool diff --git a/proxmox/config_qemu_memory.go b/proxmox/config_qemu_memory.go index e85c0be2..baa7e301 100644 --- a/proxmox/config_qemu_memory.go +++ b/proxmox/config_qemu_memory.go @@ -1,7 +1,7 @@ package proxmox import ( - "fmt" + "errors" "github.com/Telmate/proxmox-api-go/internal/parse" ) @@ -87,7 +87,7 @@ func (config QemuMemory) Validate(current *QemuMemory) error { return err } if config.CapacityMiB != nil && QemuMemoryCapacity(*config.MinimumCapacityMiB) > *config.CapacityMiB { - return fmt.Errorf(QemuMemory_Error_MinimumCapacityMiB_GreaterThan_CapacityMiB) + return errors.New(QemuMemory_Error_MinimumCapacityMiB_GreaterThan_CapacityMiB) } eventualMinimumCapacityMiB = *config.MinimumCapacityMiB eventualCapacityMiB = QemuMemoryCapacity(eventualMinimumCapacityMiB) @@ -103,7 +103,7 @@ func (config QemuMemory) Validate(current *QemuMemory) error { eventualCapacityMiB = *current.CapacityMiB } if eventualCapacityMiB == 0 { - return fmt.Errorf(QemuMemory_Error_NoMemoryCapacity) + return errors.New(QemuMemory_Error_NoMemoryCapacity) } if config.Shares != nil { if err := config.Shares.Validate(); err != nil { @@ -111,7 +111,7 @@ func (config QemuMemory) Validate(current *QemuMemory) error { } if *config.Shares > 0 { if eventualCapacityMiB == QemuMemoryCapacity(eventualMinimumCapacityMiB) { - return fmt.Errorf(QemuMemory_Error_SharesHasNoEffectWithoutBallooning) + return errors.New(QemuMemory_Error_SharesHasNoEffectWithoutBallooning) } } } @@ -127,7 +127,7 @@ const ( func (m QemuMemoryBalloonCapacity) Validate() error { if m > qemuMemoryBalloonCapacity_Max { - return fmt.Errorf(QemuMemoryBalloonCapacity_Error_Invalid) + return errors.New(QemuMemoryBalloonCapacity_Error_Invalid) } return nil } @@ -142,10 +142,10 @@ const ( func (m QemuMemoryCapacity) Validate() error { if m == 0 { - return fmt.Errorf(QemuMemoryCapacity_Error_Minimum) + return errors.New(QemuMemoryCapacity_Error_Minimum) } if m > qemuMemoryCapacity_Max { - return fmt.Errorf(QemuMemoryCapacity_Error_Maximum) + return errors.New(QemuMemoryCapacity_Error_Maximum) } return nil } @@ -159,7 +159,7 @@ const ( func (m QemuMemoryShares) Validate() error { if m > qemuMemoryShares_Max { - return fmt.Errorf(QemuMemoryShares_Error_Invalid) + return errors.New(QemuMemoryShares_Error_Invalid) } return nil } diff --git a/proxmox/snapshot.go b/proxmox/snapshot.go index e78ea87c..363f904b 100644 --- a/proxmox/snapshot.go +++ b/proxmox/snapshot.go @@ -2,6 +2,7 @@ package proxmox import ( "encoding/json" + "errors" "fmt" "regexp" "strconv" @@ -200,15 +201,15 @@ func (name SnapshotName) Validate() error { regex, _ := regexp.Compile(`^([a-zA-Z])([a-z]|[A-Z]|[0-9]|_|-){2,39}$`) if !regex.Match([]byte(name)) { if len(name) < 3 { - return fmt.Errorf(SnapshotName_Error_MinLength) + return errors.New(SnapshotName_Error_MinLength) } if len(name) > 40 { - return fmt.Errorf(SnapshotName_Error_MaxLength) + return errors.New(SnapshotName_Error_MaxLength) } if !unicode.IsLetter(rune(name[0])) { - return fmt.Errorf(SnapshotName_Error_StartNoLetter) + return errors.New(SnapshotName_Error_StartNoLetter) } - return fmt.Errorf(SnapshotName_Error_IllegalCharacters) + return errors.New(SnapshotName_Error_IllegalCharacters) } return nil }