Skip to content

Commit 58e8e99

Browse files
committed
use short if where possible
1 parent 461ed50 commit 58e8e99

9 files changed

+18
-25
lines changed

libvirt/network_def_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ func TestNetworkDefUnmarshall(t *testing.T) {
8080
if len(b.IPs) == 0 {
8181
t.Errorf("wrong number of IPs: %d", len(b.IPs))
8282
}
83-
_, err2 := xmlMarshallIndented(b)
84-
if err2 != nil {
83+
if _, err2 := xmlMarshallIndented(b); err2 != nil {
8584
t.Fatalf("marshalling error\n%s", spew.Sdump(b))
8685
}
8786
}

libvirt/resource_libvirt_cloud_init.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ func resourceCloudInitDisk() *schema.Resource {
4646

4747
func resourceCloudInitDiskCreate(d *schema.ResourceData, meta interface{}) error {
4848
log.Printf("[DEBUG] creating cloudinit")
49+
4950
client := meta.(*Client)
50-
virConn := client.libvirt
51-
if virConn == nil {
51+
if virConn := client.libvirt; virConn == nil {
5252
return fmt.Errorf(LibVirtConIsNil)
5353
}
5454

libvirt/resource_libvirt_network.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -650,24 +650,24 @@ func resourceLibvirtNetworkDelete(d *schema.ResourceData, meta interface{}) erro
650650
if err != nil {
651651
return fmt.Errorf("Couldn't determine if network is active: %s", err)
652652
}
653+
653654
// network can be in 2 states, handles this case by case
654-
active := activeInt == 1
655-
// in case network is inactive just undefine it
656-
if !active {
657-
if err := virConn.NetworkUndefine(network); err != nil {
658-
return fmt.Errorf("Couldn't undefine libvirt network: %s", err)
659-
}
660-
}
661-
// network is active, so we need to destroy it and undefine it
662-
if active {
655+
if active := int2bool(int(activeInt)); active {
656+
// network is active, so we need to destroy it and undefine it
663657
if err := virConn.NetworkDestroy(network); err != nil {
664658
return fmt.Errorf("When destroying libvirt network: %s", err)
665659
}
666660

661+
if err := virConn.NetworkUndefine(network); err != nil {
662+
return fmt.Errorf("Couldn't undefine libvirt network: %s", err)
663+
}
664+
} else {
665+
// in case network is inactive just undefine it
667666
if err := virConn.NetworkUndefine(network); err != nil {
668667
return fmt.Errorf("Couldn't undefine libvirt network: %s", err)
669668
}
670669
}
670+
671671
stateConf := &resource.StateChangeConf{
672672
Pending: []string{"ACTIVE"},
673673
Target: []string{"NOT-EXISTS"},

libvirt/resource_libvirt_pool.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@ func resourceLibvirtPoolRead(d *schema.ResourceData, meta interface{}) error {
219219
d.Set("path", poolPath)
220220
}
221221

222-
poolType := poolDef.Type
223-
if poolType == "" {
222+
if poolType := poolDef.Type; poolType == "" {
224223
log.Printf("Pool %s has no type specified", pool.Name)
225224
} else {
226225
log.Printf("[DEBUG] Pool %s type: %s", pool.Name, poolType)

libvirt/uri/connection_uri.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ func Parse(uriStr string) (*ConnectionURI, error) {
3333
// unless the name option is specified.
3434
func (u *ConnectionURI) RemoteName() string {
3535
q := u.Query()
36-
name := q.Get("name")
37-
if name != "" {
36+
if name := q.Get("name"); name != "" {
3837
return name
3938
}
4039

libvirt/uri/tls.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ func (u *ConnectionURI) tlsConfig() (*tls.Config, error) {
6767
clientKeySearchPath := []string{defaultGlobalClientKeyPath}
6868

6969
q := u.Query()
70-
pkipath := q.Get("pkipath")
7170
// if pkipath is provided, certs should all exist there
72-
if pkipath != "" {
71+
if pkipath := q.Get("pkipath"); pkipath != "" {
7372
caCertSearchPath = []string{pkipath}
7473
clientCertSearchPath = []string{pkipath}
7574
clientKeySearchPath = []string{pkipath}

libvirt/utils_libvirt_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ func TestParseUUID(t *testing.T) {
1515
t.Errorf("expected UUID %q, got %q", wantUUID, uuid)
1616
}
1717

18-
uuidToStr := uuidString(uuid)
19-
if uuidToStr != uuidStr {
18+
if uuidToStr := uuidString(uuid); uuidToStr != uuidStr {
2019
t.Errorf("expected UUID %q, got %q", uuidStr, uuidToStr)
2120
}
2221
}

libvirt/utils_net.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ func (l *networkUpdateWorkaroundLibvirt) NetworkUpdate(Net libvirt.Network, Comm
4343
func randomMACAddress() (string, error) {
4444
buf := make([]byte, 3)
4545
rand.Seed(time.Now().UnixNano())
46-
_, err := rand.Read(buf)
47-
if err != nil {
46+
if _, err := rand.Read(buf); err != nil {
4847
return "", err
4948
}
5049

main_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import (
88

99
func TestPrintVersion(t *testing.T) {
1010
buf := &bytes.Buffer{}
11-
err := printVersion(buf)
12-
if err != nil {
11+
if err := printVersion(buf); err != nil {
1312
t.Fatal(err)
1413
}
1514
output := buf.Bytes()

0 commit comments

Comments
 (0)