Merge lp:~jtv/gwacl/gofmt-simplify into lp:gwacl

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Jeroen T. Vermeulen
Approved revision: 73
Merged at revision: 76
Proposed branch: lp:~jtv/gwacl/gofmt-simplify
Merge into: lp:gwacl
Diff against target: 124 lines (+19/-19)
4 files modified
poller_test.go (+4/-4)
storage_test.go (+8/-8)
test_helpers.go (+1/-1)
xmlobjects_test.go (+6/-6)
To merge this branch: bzr merge lp:~jtv/gwacl/gofmt-simplify
Reviewer Review Type Date Requested Status
Raphaël Badin (community) Approve
Review via email: mp+156098@code.launchpad.net

Commit message

Clean up some small nuisances using gofmt's -s ("simplify") option.

Description of the change

Maybe we should always run this as part of formatting: gofmt's “-s” option streamlines the code a bit.

I also tried it on gomaasapi and even juju-core, and the only things I saw it clean up were:

 1. Unneeded specifications on initializers, such as array literals inside array literals. That's what you see here.

 2. Use of “_” as the optional second iteration output: “for x, _ := range y” becomes “for x := range y”.

So it looks pretty safe. There are also options to list files that gofmt _would_ change if you allowed it to, and for showing what changes it would like to make.

Jeroen

To post a comment you must log in.
Revision history for this message
Raphaël Badin (rvb) wrote :

Looks good! I didn't know that option existed.

> Maybe we should always run this as part of formatting: gofmt's “-s” option streamlines the code a bit.

I think we should.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'poller_test.go'
2--- poller_test.go 2013-03-28 10:46:07 +0000
3+++ poller_test.go 2013-03-29 01:34:22 +0000
4@@ -130,14 +130,14 @@
5 poller := NewOperationPoller(suite.makeAPI(c), "operationID")
6 notDoneResponses := []x509Response{
7 // 'InProgress' response.
8- x509Response{
9+ {
10 Body: []byte(fmt.Sprintf(operationXMLTemplate, "InProgress")),
11 StatusCode: http.StatusOK,
12 },
13 // Error statuses.
14- x509Response{StatusCode: http.StatusNotFound},
15- x509Response{StatusCode: http.StatusBadRequest},
16- x509Response{StatusCode: http.StatusInternalServerError},
17+ {StatusCode: http.StatusNotFound},
18+ {StatusCode: http.StatusBadRequest},
19+ {StatusCode: http.StatusInternalServerError},
20 }
21 for _, response := range notDoneResponses {
22 isDone, _ := poller.isDone(&response)
23
24=== modified file 'storage_test.go'
25--- storage_test.go 2013-03-27 07:16:45 +0000
26+++ storage_test.go 2013-03-29 01:34:22 +0000
27@@ -106,10 +106,10 @@
28
29 observed := toLowerKeys(values)
30 expected := map[string][]string{
31- "foo": []string{"bar", "baz"},
32- "alpha": []string{"delta", "gamma"},
33- "quux": []string{"flobble"},
34- "big": []string{"Big", "Big", "Data", "Little"},
35+ "foo": {"bar", "baz"},
36+ "alpha": {"delta", "gamma"},
37+ "quux": {"flobble"},
38+ "big": {"Big", "Big", "Data", "Little"},
39 }
40
41 c.Check(observed, DeepEquals, expected)
42@@ -117,10 +117,10 @@
43
44 func (suite *TestComposeCanonicalizedResource) TestEncodeParams(c *C) {
45 input := map[string][]string{
46- "foo": []string{"bar", "baz"},
47- "alpha": []string{"delta", "gamma"},
48- "quux": []string{"flobble"},
49- "big": []string{"Big", "Big", "Data", "Little"},
50+ "foo": {"bar", "baz"},
51+ "alpha": {"delta", "gamma"},
52+ "quux": {"flobble"},
53+ "big": {"Big", "Big", "Data", "Little"},
54 }
55
56 observed := encodeParams(input)
57
58=== modified file 'test_helpers.go'
59--- test_helpers.go 2013-03-27 08:44:24 +0000
60+++ test_helpers.go 2013-03-29 01:34:22 +0000
61@@ -167,7 +167,7 @@
62 AffinityGroup := MakeRandomString(10)
63 Location := MakeRandomString(10)
64 GeoReplicationEnabled := BoolToString(MakeRandomBool())
65- ExtendedProperties := []ExtendedProperty{ExtendedProperty{
66+ ExtendedProperties := []ExtendedProperty{{
67 Name: MakeRandomString(10),
68 Value: MakeRandomString(10)}}
69
70
71=== modified file 'xmlobjects_test.go'
72--- xmlobjects_test.go 2013-03-27 07:16:45 +0000
73+++ xmlobjects_test.go 2013-03-29 01:34:22 +0000
74@@ -522,7 +522,7 @@
75
76 expected := &Metadata{
77 Items: []MetadataItem{
78- MetadataItem{
79+ {
80 XMLName: xml.Name{Local: "metadata-name"},
81 Value: "metadata-value",
82 },
83@@ -567,7 +567,7 @@
84 },
85 Metadata: Metadata{
86 Items: []MetadataItem{
87- MetadataItem{
88+ {
89 XMLName: xml.Name{Local: "metadata-name"},
90 Value: "metadata-value",
91 },
92@@ -614,7 +614,7 @@
93 Marker: "marker-value",
94 MaxResults: "max-results-value",
95 Containers: []Container{
96- Container{
97+ {
98 XMLName: xml.Name{Local: "Container"},
99 Name: "name-value",
100 URL: "url-value",
101@@ -627,7 +627,7 @@
102 },
103 Metadata: Metadata{
104 Items: []MetadataItem{
105- MetadataItem{
106+ {
107 XMLName: xml.Name{Local: "metadata-name"},
108 Value: "metadata-value",
109 },
110@@ -702,12 +702,12 @@
111 expected := GetBlockList{
112 XMLName: xml.Name{Local: "BlockList"},
113 CommittedBlocks: []Block{
114- Block{
115+ {
116 Name: "BlockId001",
117 Size: "4194304"},
118 },
119 UncommittedBlocks: []Block{
120- Block{
121+ {
122 Name: "BlockId002",
123 Size: "1024"},
124 },

Subscribers

People subscribed via source and target branches