remove unnecessary type conversions

This commit is contained in:
Matthew Hooker 2017-03-28 18:47:10 -07:00
parent bf64d7bdc2
commit 35578d9ed1
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
13 changed files with 58 additions and 55 deletions

View File

@ -115,5 +115,5 @@ func GetInstanceMetaData(path string) (contents []byte, err error) {
if err != nil {
return
}
return []byte(body), err
return body, err
}

View File

@ -163,7 +163,7 @@ func WaitForState(conf *StateChangeConf) (i interface{}, err error) {
log.Printf("Waiting for state to become: %s", conf.Target)
sleepSeconds := SleepSeconds()
maxTicks := int(TimeoutSeconds()/sleepSeconds) + 1
maxTicks := TimeoutSeconds()/sleepSeconds + 1
notfoundTick := 0
for {

View File

@ -18,5 +18,5 @@ func GlueStrings(a, b string) string {
shift++
}
return string(a[:shift]) + b
return a[:shift] + b
}

View File

@ -44,7 +44,7 @@ func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) {
return nil, fmt.Errorf("Error loading configured private key file: %s", err)
}
signer, err := ssh.ParsePrivateKey([]byte(privateKey))
signer, err := ssh.ParsePrivateKey(privateKey)
if err != nil {
return nil, fmt.Errorf("Error setting up SSH config: %s", err)
}

View File

@ -3,10 +3,11 @@ package digitalocean
import (
"fmt"
"io/ioutil"
"github.com/digitalocean/godo"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"io/ioutil"
)
type stepCreateDroplet struct {
@ -41,7 +42,7 @@ func (s *stepCreateDroplet) Run(state multistep.StateBag) multistep.StepAction {
Slug: c.Image,
},
SSHKeys: []godo.DropletCreateSSHKey{
{ID: int(sshKeyId)},
{ID: sshKeyId},
},
PrivateNetworking: c.PrivateNetworking,
UserData: userData,

View File

@ -254,7 +254,7 @@ func (d *HypervPS4Driver) verifyPSVersion() error {
return err
}
versionOutput := strings.TrimSpace(string(cmdOut))
versionOutput := strings.TrimSpace(cmdOut)
log.Printf("%s output: %s", versionCmd, versionOutput)
ver, err := strconv.ParseInt(versionOutput, 10, 32)
@ -283,7 +283,7 @@ func (d *HypervPS4Driver) verifyPSHypervModule() error {
return err
}
res := strings.TrimSpace(string(cmdOut))
res := strings.TrimSpace(cmdOut)
if res == "False" {
err := fmt.Errorf("%s", "PS Hyper-V module is not loaded. Make sure Hyper-V feature is on.")
@ -305,7 +305,7 @@ func (d *HypervPS4Driver) verifyHypervPermissions() error {
return err
}
res := strings.TrimSpace(string(cmdOut))
res := strings.TrimSpace(cmdOut)
if res == "False" {
isAdmin, _ := powershell.IsCurrentUserAnAdministrator()

View File

@ -2,11 +2,12 @@ package common
import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
"strings"
"time"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
)
type StepConfigureIp struct {
@ -35,7 +36,7 @@ func (s *StepConfigureIp) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt
}
ip = strings.TrimSpace(string(cmdOut))
ip = strings.TrimSpace(cmdOut)
if ip != "False" {
break

View File

@ -59,7 +59,7 @@ func (c *AccessConfig) CreateTritonClient() (*cloudapi.Client, error) {
return nil, err
}
userauth, err := auth.NewAuth(c.Account, string(keyData), "rsa-sha256")
userauth, err := auth.NewAuth(c.Account, keyData, "rsa-sha256")
if err != nil {
return nil, err
}

View File

@ -15,7 +15,7 @@ func CommHost(host string) func(multistep.StateBag) (string, error) {
func SSHPort(state multistep.StateBag) (int, error) {
sshHostPort := state.Get("sshHostPort").(int)
return int(sshHostPort), nil
return sshHostPort, nil
}
func SSHConfigFunc(config SSHConfig) func(multistep.StateBag) (*gossh.ClientConfig, error) {

View File

@ -721,7 +721,7 @@ $vm.Uptime.TotalSeconds
return 0, err
}
uptime, err := strconv.ParseUint(strings.TrimSpace(string(cmdOut)), 10, 64)
uptime, err := strconv.ParseUint(strings.TrimSpace(cmdOut), 10, 64)
return uptime, err
}

View File

@ -219,7 +219,7 @@ param([string]$moduleName)
return false, err
}
res := strings.TrimSpace(string(cmdOut))
res := strings.TrimSpace(cmdOut)
if res == powerShellFalse {
err := fmt.Errorf("PowerShell %s module is not loaded. Make sure %s feature is on.", moduleName, moduleName)

View File

@ -1,8 +1,9 @@
package ssh
import (
"golang.org/x/crypto/ssh"
"log"
"golang.org/x/crypto/ssh"
)
// An implementation of ssh.KeyboardInteractiveChallenge that simply sends
@ -19,7 +20,7 @@ func PasswordKeyboardInteractive(password string) ssh.KeyboardInteractiveChallen
// Just send the password back for all questions
answers := make([]string, len(questions))
for i := range answers {
answers[i] = string(password)
answers[i] = password
}
return answers, nil

View File

@ -321,7 +321,7 @@ func scpResponse(r *bufio.Reader) error {
// 1 is a warning. Anything higher (really just 2) is an error.
if code > 1 {
return errors.New(string(message))
return errors.New(message)
}
log.Println("WARNING:", err)