Skip to content

Commit aa0ba48

Browse files
authored
Add gofmt and golint linters (terraform-provider-openstack#1076)
* Add gofmt linter * Add golint linter
1 parent 070c4c9 commit aa0ba48

251 files changed

Lines changed: 2140 additions & 2154 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.golangci.yml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ linters:
1414
# - errcheck
1515
- exhaustive
1616
- exportloopref
17+
# - gochecknoglobals
1718
# - goconst
1819
# - gocritic
1920
- godot
20-
# - gofmt
21+
- gofmt
2122
# - gofumpt
2223
- goheader
2324
- goimports
24-
# - golint
25+
- golint
2526
# - gomodguard
2627
# - goprintffuncname
2728
# - gosec

‎openstack/compute_floatingip_associate_v2.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ import (
1212
nfloatingips "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips"
1313
)
1414

15-
func parseComputeFloatingIPAssociateId(id string) (string, string, string, error) {
15+
func parseComputeFloatingIPAssociateID(id string) (string, string, string, error) {
1616
idParts := strings.Split(id, "/")
1717
if len(idParts) < 3 {
1818
return "", "", "", fmt.Errorf("Unable to determine floating ip association ID")
1919
}
2020

2121
floatingIP := idParts[0]
22-
instanceId := idParts[1]
22+
instanceID := idParts[1]
2323
fixedIP := idParts[2]
2424

25-
return floatingIP, instanceId, fixedIP, nil
25+
return floatingIP, instanceID, fixedIP, nil
2626
}
2727

2828
func computeFloatingIPAssociateV2NetworkExists(networkClient *gophercloud.ServiceClient, floatingIP string) (bool, error) {
@@ -72,9 +72,9 @@ func computeFloatingIPAssociateV2ComputeExists(computeClient *gophercloud.Servic
7272
}
7373

7474
func computeFloatingIPAssociateV2CheckAssociation(
75-
computeClient *gophercloud.ServiceClient, instanceId, floatingIP string) resource.StateRefreshFunc {
75+
computeClient *gophercloud.ServiceClient, instanceID, floatingIP string) resource.StateRefreshFunc {
7676
return func() (interface{}, string, error) {
77-
instance, err := servers.Get(computeClient, instanceId).Extract()
77+
instance, err := servers.Get(computeClient, instanceID).Extract()
7878
if err != nil {
7979
return instance, "", err
8080
}

‎openstack/compute_instance_v2.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func getAllInstanceNetworks(d *schema.ResourceData, meta interface{}) ([]Instanc
8787

8888
if networkID == "" && networkName == "" && portID == "" {
8989
return nil, fmt.Errorf(
90-
"At least one of network.uuid, network.name, or network.port must be set.")
90+
"At least one of network.uuid, network.name, or network.port must be set")
9191
}
9292

9393
// If a user specified both an ID and name, that makes things easy

‎openstack/compute_interface_attach_v2.go‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212
)
1313

1414
func computeInterfaceAttachV2AttachFunc(
15-
computeClient *gophercloud.ServiceClient, instanceId, attachmentId string) resource.StateRefreshFunc {
15+
computeClient *gophercloud.ServiceClient, instanceID, attachmentID string) resource.StateRefreshFunc {
1616
return func() (interface{}, string, error) {
17-
va, err := attachinterfaces.Get(computeClient, instanceId, attachmentId).Extract()
17+
va, err := attachinterfaces.Get(computeClient, instanceID, attachmentID).Extract()
1818
if err != nil {
1919
if _, ok := err.(gophercloud.ErrDefault404); ok {
2020
return va, "ATTACHING", nil
@@ -27,20 +27,20 @@ func computeInterfaceAttachV2AttachFunc(
2727
}
2828

2929
func computeInterfaceAttachV2DetachFunc(
30-
computeClient *gophercloud.ServiceClient, instanceId, attachmentId string) resource.StateRefreshFunc {
30+
computeClient *gophercloud.ServiceClient, instanceID, attachmentID string) resource.StateRefreshFunc {
3131
return func() (interface{}, string, error) {
3232
log.Printf("[DEBUG] Attempting to detach openstack_compute_interface_attach_v2 %s from instance %s",
33-
attachmentId, instanceId)
33+
attachmentID, instanceID)
3434

35-
va, err := attachinterfaces.Get(computeClient, instanceId, attachmentId).Extract()
35+
va, err := attachinterfaces.Get(computeClient, instanceID, attachmentID).Extract()
3636
if err != nil {
3737
if _, ok := err.(gophercloud.ErrDefault404); ok {
3838
return va, "DETACHED", nil
3939
}
4040
return va, "", err
4141
}
4242

43-
err = attachinterfaces.Delete(computeClient, instanceId, attachmentId).ExtractErr()
43+
err = attachinterfaces.Delete(computeClient, instanceID, attachmentID).ExtractErr()
4444
if err != nil {
4545
if _, ok := err.(gophercloud.ErrDefault404); ok {
4646
return va, "DETACHED", nil
@@ -53,7 +53,7 @@ func computeInterfaceAttachV2DetachFunc(
5353
return nil, "", err
5454
}
5555

56-
log.Printf("[DEBUG] openstack_compute_interface_attach_v2 %s is still active.", attachmentId)
56+
log.Printf("[DEBUG] openstack_compute_interface_attach_v2 %s is still active.", attachmentID)
5757
return nil, "", nil
5858
}
5959
}
@@ -64,8 +64,8 @@ func computeInterfaceAttachV2ParseID(id string) (string, string, error) {
6464
return "", "", fmt.Errorf("Unable to determine openstack_compute_interface_attach_v2 %s ID", id)
6565
}
6666

67-
instanceId := idParts[0]
68-
attachmentId := idParts[1]
67+
instanceID := idParts[0]
68+
attachmentID := idParts[1]
6969

70-
return instanceId, attachmentId, nil
70+
return instanceID, attachmentID, nil
7171
}

‎openstack/compute_secgroup_v2.go‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,27 @@ func computeSecGroupV2RulesCheckForErrors(d *schema.ResourceData) error {
2121

2222
// only one of cidr, from_group_id, or self can be set
2323
cidr := rawRuleMap["cidr"].(string)
24-
groupId := rawRuleMap["from_group_id"].(string)
24+
groupID := rawRuleMap["from_group_id"].(string)
2525
self := rawRuleMap["self"].(bool)
26-
errorMessage := fmt.Errorf("Only one of cidr, from_group_id, or self can be set.")
26+
errorMessage := fmt.Errorf("Only one of cidr, from_group_id, or self can be set")
2727

2828
// if cidr is set, from_group_id and self cannot be set
2929
if cidr != "" {
30-
if groupId != "" || self {
30+
if groupID != "" || self {
3131
return errorMessage
3232
}
3333
}
3434

3535
// if from_group_id is set, cidr and self cannot be set
36-
if groupId != "" {
36+
if groupID != "" {
3737
if cidr != "" || self {
3838
return errorMessage
3939
}
4040
}
4141

4242
// if self is set, cidr and from_group_id cannot be set
4343
if self {
44-
if cidr != "" || groupId != "" {
44+
if cidr != "" || groupID != "" {
4545
return errorMessage
4646
}
4747
}
@@ -63,17 +63,17 @@ func expandComputeSecGroupV2CreateRules(d *schema.ResourceData) []secgroups.Crea
6363

6464
func expandComputeSecGroupV2CreateRule(d *schema.ResourceData, rawRule interface{}) secgroups.CreateRuleOpts {
6565
rawRuleMap := rawRule.(map[string]interface{})
66-
groupId := rawRuleMap["from_group_id"].(string)
66+
groupID := rawRuleMap["from_group_id"].(string)
6767
if rawRuleMap["self"].(bool) {
68-
groupId = d.Id()
68+
groupID = d.Id()
6969
}
7070
return secgroups.CreateRuleOpts{
7171
ParentGroupID: d.Id(),
7272
FromPort: rawRuleMap["from_port"].(int),
7373
ToPort: rawRuleMap["to_port"].(int),
7474
IPProtocol: rawRuleMap["ip_protocol"].(string),
7575
CIDR: rawRuleMap["cidr"].(string),
76-
FromGroupID: groupId,
76+
FromGroupID: groupID,
7777
}
7878
}
7979

@@ -92,7 +92,7 @@ func expandComputeSecGroupV2Rule(d *schema.ResourceData, rawRule interface{}) se
9292
func flattenComputeSecGroupV2Rules(computeClient *gophercloud.ServiceClient, d *schema.ResourceData, sgrs []secgroups.Rule) ([]map[string]interface{}, error) {
9393
sgrMap := make([]map[string]interface{}, len(sgrs))
9494
for i, sgr := range sgrs {
95-
groupId := ""
95+
groupID := ""
9696
self := false
9797
if sgr.Group.Name != "" {
9898
if sgr.Group.Name == d.Get("name").(string) {
@@ -113,7 +113,7 @@ func flattenComputeSecGroupV2Rules(computeClient *gophercloud.ServiceClient, d *
113113

114114
for _, sg := range securityGroups {
115115
if sg.Name == sgr.Group.Name {
116-
groupId = sg.ID
116+
groupID = sg.ID
117117
}
118118
}
119119
}
@@ -126,7 +126,7 @@ func flattenComputeSecGroupV2Rules(computeClient *gophercloud.ServiceClient, d *
126126
"ip_protocol": sgr.IPProtocol,
127127
"cidr": sgr.IPRange.CIDR,
128128
"self": self,
129-
"from_group_id": groupId,
129+
"from_group_id": groupID,
130130
}
131131
}
132132
return sgrMap, nil

‎openstack/compute_volume_attach_v2.go‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ func computeVolumeAttachV2ParseID(id string) (string, string, error) {
2323
return instanceID, attachmentID, nil
2424
}
2525

26-
func computeVolumeAttachV2AttachFunc(
27-
computeClient *gophercloud.ServiceClient, instanceId, attachmentId string) resource.StateRefreshFunc {
26+
func computeVolumeAttachV2AttachFunc(computeClient *gophercloud.ServiceClient, instanceID, attachmentID string) resource.StateRefreshFunc {
2827
return func() (interface{}, string, error) {
29-
va, err := volumeattach.Get(computeClient, instanceId, attachmentId).Extract()
28+
va, err := volumeattach.Get(computeClient, instanceID, attachmentID).Extract()
3029
if err != nil {
3130
if _, ok := err.(gophercloud.ErrDefault404); ok {
3231
return va, "ATTACHING", nil
@@ -38,21 +37,20 @@ func computeVolumeAttachV2AttachFunc(
3837
}
3938
}
4039

41-
func computeVolumeAttachV2DetachFunc(
42-
computeClient *gophercloud.ServiceClient, instanceId, attachmentId string) resource.StateRefreshFunc {
40+
func computeVolumeAttachV2DetachFunc(computeClient *gophercloud.ServiceClient, instanceID, attachmentID string) resource.StateRefreshFunc {
4341
return func() (interface{}, string, error) {
4442
log.Printf("[DEBUG] openstack_compute_volume_attach_v2 attempting to detach OpenStack volume %s from instance %s",
45-
attachmentId, instanceId)
43+
attachmentID, instanceID)
4644

47-
va, err := volumeattach.Get(computeClient, instanceId, attachmentId).Extract()
45+
va, err := volumeattach.Get(computeClient, instanceID, attachmentID).Extract()
4846
if err != nil {
4947
if _, ok := err.(gophercloud.ErrDefault404); ok {
5048
return va, "DETACHED", nil
5149
}
5250
return va, "", err
5351
}
5452

55-
err = volumeattach.Delete(computeClient, instanceId, attachmentId).ExtractErr()
53+
err = volumeattach.Delete(computeClient, instanceID, attachmentID).ExtractErr()
5654
if err != nil {
5755
if _, ok := err.(gophercloud.ErrDefault404); ok {
5856
return va, "DETACHED", nil
@@ -65,7 +63,7 @@ func computeVolumeAttachV2DetachFunc(
6563
return nil, "", err
6664
}
6765

68-
log.Printf("[DEBUG] openstack_compute_volume_attach_v2 (%s/%s) is still active.", instanceId, attachmentId)
66+
log.Printf("[DEBUG] openstack_compute_volume_attach_v2 (%s/%s) is still active.", instanceID, attachmentID)
6967
return nil, "", nil
7068
}
7169
}

‎openstack/containerinfra_shared_v1_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ func TestExpandContainerInfraV1LabelsString(t *testing.T) {
3030
"bar": "baz",
3131
}
3232

33-
expectedLabels_1 := "foo=bar,bar=baz"
34-
expectedLabels_2 := "bar=baz,foo=bar"
33+
expectedLabels1 := "foo=bar,bar=baz"
34+
expectedLabels2 := "bar=baz,foo=bar"
3535

3636
actualLabels, err := expandContainerInfraV1LabelsString(labels)
3737
assert.Equal(t, err, nil)
3838

39-
if actualLabels != expectedLabels_1 && actualLabels != expectedLabels_2 {
39+
if actualLabels != expectedLabels1 && actualLabels != expectedLabels2 {
4040
t.Fatalf("Unexpected labels. Got %s, expected %s or %s",
41-
actualLabels, expectedLabels_1, expectedLabels_2)
41+
actualLabels, expectedLabels1, expectedLabels2)
4242
}
4343
}
4444

‎openstack/data_source_openstack_blockstorage_snapshot_v2_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestAccBlockStorageV2SnapshotDataSource_basic(t *testing.T) {
3434
Providers: testAccProviders,
3535
Steps: []resource.TestStep{
3636
{
37-
Config: testAccBlockStorageV2SnapshotDataSource_basic(snapshotName),
37+
Config: testAccBlockStorageV2SnapshotDataSourceBasic(snapshotName),
3838
Check: resource.ComposeTestCheckFunc(
3939
testAccCheckBlockStorageV2SnapshotDataSourceID(resourceName),
4040
resource.TestCheckResourceAttr(resourceName, "name", snapshotName),
@@ -51,7 +51,7 @@ func testAccBlockStorageV2CreateVolumeAndSnapshot(volumeName, snapshotName strin
5151
return "", "", err
5252
}
5353

54-
bsClient, err := config.BlockStorageV2Client(OS_REGION_NAME)
54+
bsClient, err := config.BlockStorageV2Client(osRegionName)
5555
if err != nil {
5656
return "", "", err
5757
}
@@ -95,7 +95,7 @@ func testAccBlockStorageV2DeleteVolumeAndSnapshot(t *testing.T, volumeID, snapsh
9595
t.Fatal(err)
9696
}
9797

98-
bsClient, err := config.BlockStorageV2Client(OS_REGION_NAME)
98+
bsClient, err := config.BlockStorageV2Client(osRegionName)
9999
if err != nil {
100100
t.Fatal(err)
101101
}
@@ -140,7 +140,7 @@ func testAccCheckBlockStorageV2SnapshotDataSourceID(n string) resource.TestCheck
140140
}
141141
}
142142

143-
func testAccBlockStorageV2SnapshotDataSource_basic(snapshotName string) string {
143+
func testAccBlockStorageV2SnapshotDataSourceBasic(snapshotName string) string {
144144
return fmt.Sprintf(`
145145
data "openstack_blockstorage_snapshot_v2" "snapshot_1" {
146146
name = "%s"

‎openstack/data_source_openstack_blockstorage_snapshot_v3_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestAccBlockStorageV3SnapshotDataSource_basic(t *testing.T) {
3434
Providers: testAccProviders,
3535
Steps: []resource.TestStep{
3636
{
37-
Config: testAccBlockStorageV3SnapshotDataSource_basic(snapshotName),
37+
Config: testAccBlockStorageV3SnapshotDataSourceBasic(snapshotName),
3838
Check: resource.ComposeTestCheckFunc(
3939
testAccCheckBlockStorageV3SnapshotDataSourceID(resourceName),
4040
resource.TestCheckResourceAttr(resourceName, "name", snapshotName),
@@ -51,7 +51,7 @@ func testAccBlockStorageV3CreateVolumeAndSnapshot(volumeName, snapshotName strin
5151
return "", "", err
5252
}
5353

54-
bsClient, err := config.BlockStorageV3Client(OS_REGION_NAME)
54+
bsClient, err := config.BlockStorageV3Client(osRegionName)
5555
if err != nil {
5656
return "", "", err
5757
}
@@ -95,7 +95,7 @@ func testAccBlockStorageV3DeleteVolumeAndSnapshot(t *testing.T, volumeID, snapsh
9595
t.Fatal(err)
9696
}
9797

98-
bsClient, err := config.BlockStorageV3Client(OS_REGION_NAME)
98+
bsClient, err := config.BlockStorageV3Client(osRegionName)
9999
if err != nil {
100100
t.Fatal(err)
101101
}
@@ -140,7 +140,7 @@ func testAccCheckBlockStorageV3SnapshotDataSourceID(n string) resource.TestCheck
140140
}
141141
}
142142

143-
func testAccBlockStorageV3SnapshotDataSource_basic(snapshotName string) string {
143+
func testAccBlockStorageV3SnapshotDataSourceBasic(snapshotName string) string {
144144
return fmt.Sprintf(`
145145
data "openstack_blockstorage_snapshot_v3" "snapshot_1" {
146146
name = "%s"

‎openstack/data_source_openstack_blockstorage_volume_v2.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ func dataSourceBlockStorageVolumeV2Read(d *schema.ResourceData, meta interface{}
8888
}
8989

9090
if len(allVolumes) > 1 {
91-
return fmt.Errorf("Your openstack_blockstorage_volume_v2 query returned multiple results.")
91+
return fmt.Errorf("Your openstack_blockstorage_volume_v2 query returned multiple results")
9292
}
9393

9494
if len(allVolumes) < 1 {
95-
return fmt.Errorf("Your openstack_blockstorage_volume_v2 query returned no results.")
95+
return fmt.Errorf("Your openstack_blockstorage_volume_v2 query returned no results")
9696
}
9797

9898
return dataSourceBlockStorageVolumeV2Attributes(d, allVolumes[0])

0 commit comments

Comments
 (0)