Skip to content

Commit

Permalink
Merge pull request #357 from Tinyblargon/fix-staticcheck
Browse files Browse the repository at this point in the history
Fix staticcheck
  • Loading branch information
Tinyblargon authored Aug 15, 2024
2 parents 4d06080 + e108614 commit 602cfe7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
5 changes: 3 additions & 2 deletions proxmox/config_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"errors"
"regexp"
"strconv"

"github.com/Telmate/proxmox-api-go/internal/util"
)

func ListPools(c *Client) ([]PoolName, error) {
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions proxmox/config_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
11 changes: 5 additions & 6 deletions proxmox/config_qemu_cloudinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"regexp"
"strconv"
"strings"

"github.com/Telmate/proxmox-api-go/internal/util"
)

var regexMultipleNewlineEncoded = regexp.MustCompile(`(%0A)+`)
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions proxmox/config_qemu_memory.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package proxmox

import (
"fmt"
"errors"

"github.com/Telmate/proxmox-api-go/internal/parse"
)
Expand Down Expand Up @@ -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)
Expand All @@ -103,15 +103,15 @@ 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 {
return err
}
if *config.Shares > 0 {
if eventualCapacityMiB == QemuMemoryCapacity(eventualMinimumCapacityMiB) {
return fmt.Errorf(QemuMemory_Error_SharesHasNoEffectWithoutBallooning)
return errors.New(QemuMemory_Error_SharesHasNoEffectWithoutBallooning)
}
}
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
9 changes: 5 additions & 4 deletions proxmox/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package proxmox

import (
"encoding/json"
"errors"
"fmt"
"regexp"
"strconv"
Expand Down Expand Up @@ -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
}

0 comments on commit 602cfe7

Please sign in to comment.