From 6b23a8131f36443b0f0d1f78e0eee492b220299d Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Fri, 21 Aug 2015 18:52:16 -0700 Subject: [PATCH] *: test gofmt with -s and fix reported issues --- client/client_test.go | 62 ++++++++--------- client/keys_test.go | 8 +-- client/members_test.go | 16 ++--- client/srv_test.go | 28 ++++---- discovery/srv_test.go | 28 ++++---- error/error_test.go | 6 +- etcdctl/command/auth_commands.go | 4 +- etcdctl/command/member_commands.go | 8 +-- etcdctl/command/role_commands.go | 12 ++-- etcdctl/command/user_commands.go | 14 ++-- etcdmain/config_test.go | 8 +-- etcdserver/auth/auth_test.go | 8 +-- etcdserver/cluster.go | 2 +- etcdserver/cluster_test.go | 20 +++--- etcdserver/cluster_util_test.go | 32 ++++----- etcdserver/etcdhttp/client_test.go | 32 ++++----- etcdserver/etcdhttp/httptypes/errors_test.go | 2 +- etcdserver/etcdhttp/httptypes/member_test.go | 4 +- etcdserver/server.go | 2 +- etcdserver/server_test.go | 8 +-- integration/cluster_test.go | 2 +- pkg/cors/cors.go | 2 +- pkg/flags/flag_test.go | 10 +-- pkg/netutil/netutil_test.go | 72 ++++++++++---------- pkg/transport/listener_test.go | 16 ++--- pkg/types/set.go | 4 +- proxy/director_test.go | 6 +- proxy/reverse_test.go | 48 ++++++------- raft/raft_test.go | 2 +- rafthttp/stream.go | 6 +- rafthttp/transport.go | 2 +- storage/index_test.go | 30 ++++---- storage/key_index_test.go | 16 ++--- storage/revision_test.go | 10 +-- test | 2 +- 35 files changed, 266 insertions(+), 266 deletions(-) diff --git a/client/client_test.go b/client/client_test.go index 902e85543..32920ede1 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -333,8 +333,8 @@ func TestHTTPClusterClientDo(t *testing.T) { endpoints: []url.URL{fakeURL, fakeURL}, clientFactory: newStaticHTTPClientFactory( []staticHTTPResponse{ - staticHTTPResponse{resp: http.Response{StatusCode: http.StatusTeapot}}, - staticHTTPResponse{err: fakeErr}, + {resp: http.Response{StatusCode: http.StatusTeapot}}, + {err: fakeErr}, }, ), rand: rand.New(rand.NewSource(0)), @@ -348,8 +348,8 @@ func TestHTTPClusterClientDo(t *testing.T) { endpoints: []url.URL{fakeURL, fakeURL}, clientFactory: newStaticHTTPClientFactory( []staticHTTPResponse{ - staticHTTPResponse{err: fakeErr}, - staticHTTPResponse{resp: http.Response{StatusCode: http.StatusTeapot}}, + {err: fakeErr}, + {resp: http.Response{StatusCode: http.StatusTeapot}}, }, ), rand: rand.New(rand.NewSource(0)), @@ -364,8 +364,8 @@ func TestHTTPClusterClientDo(t *testing.T) { endpoints: []url.URL{fakeURL, fakeURL}, clientFactory: newStaticHTTPClientFactory( []staticHTTPResponse{ - staticHTTPResponse{err: context.Canceled}, - staticHTTPResponse{resp: http.Response{StatusCode: http.StatusTeapot}}, + {err: context.Canceled}, + {resp: http.Response{StatusCode: http.StatusTeapot}}, }, ), rand: rand.New(rand.NewSource(0)), @@ -389,8 +389,8 @@ func TestHTTPClusterClientDo(t *testing.T) { endpoints: []url.URL{fakeURL, fakeURL}, clientFactory: newStaticHTTPClientFactory( []staticHTTPResponse{ - staticHTTPResponse{err: fakeErr}, - staticHTTPResponse{err: fakeErr}, + {err: fakeErr}, + {err: fakeErr}, }, ), rand: rand.New(rand.NewSource(0)), @@ -404,8 +404,8 @@ func TestHTTPClusterClientDo(t *testing.T) { endpoints: []url.URL{fakeURL, fakeURL}, clientFactory: newStaticHTTPClientFactory( []staticHTTPResponse{ - staticHTTPResponse{resp: http.Response{StatusCode: http.StatusBadGateway}}, - staticHTTPResponse{resp: http.Response{StatusCode: http.StatusTeapot}}, + {resp: http.Response{StatusCode: http.StatusBadGateway}}, + {resp: http.Response{StatusCode: http.StatusTeapot}}, }, ), rand: rand.New(rand.NewSource(0)), @@ -513,7 +513,7 @@ func TestRedirectFollowingHTTPClient(t *testing.T) { checkRedirect: func(int) error { return ErrTooManyRedirects }, client: &multiStaticHTTPClient{ responses: []staticHTTPResponse{ - staticHTTPResponse{ + { err: errors.New("fail!"), }, }, @@ -526,7 +526,7 @@ func TestRedirectFollowingHTTPClient(t *testing.T) { checkRedirect: func(int) error { return ErrTooManyRedirects }, client: &multiStaticHTTPClient{ responses: []staticHTTPResponse{ - staticHTTPResponse{ + { resp: http.Response{ StatusCode: http.StatusTeapot, }, @@ -546,13 +546,13 @@ func TestRedirectFollowingHTTPClient(t *testing.T) { }, client: &multiStaticHTTPClient{ responses: []staticHTTPResponse{ - staticHTTPResponse{ + { resp: http.Response{ StatusCode: http.StatusTemporaryRedirect, Header: http.Header{"Location": []string{"http://example.com"}}, }, }, - staticHTTPResponse{ + { resp: http.Response{ StatusCode: http.StatusTeapot, }, @@ -572,19 +572,19 @@ func TestRedirectFollowingHTTPClient(t *testing.T) { }, client: &multiStaticHTTPClient{ responses: []staticHTTPResponse{ - staticHTTPResponse{ + { resp: http.Response{ StatusCode: http.StatusTemporaryRedirect, Header: http.Header{"Location": []string{"http://example.com"}}, }, }, - staticHTTPResponse{ + { resp: http.Response{ StatusCode: http.StatusTemporaryRedirect, Header: http.Header{"Location": []string{"http://example.com"}}, }, }, - staticHTTPResponse{ + { resp: http.Response{ StatusCode: http.StatusTeapot, }, @@ -604,19 +604,19 @@ func TestRedirectFollowingHTTPClient(t *testing.T) { }, client: &multiStaticHTTPClient{ responses: []staticHTTPResponse{ - staticHTTPResponse{ + { resp: http.Response{ StatusCode: http.StatusTemporaryRedirect, Header: http.Header{"Location": []string{"http://example.com"}}, }, }, - staticHTTPResponse{ + { resp: http.Response{ StatusCode: http.StatusTemporaryRedirect, Header: http.Header{"Location": []string{"http://example.com"}}, }, }, - staticHTTPResponse{ + { resp: http.Response{ StatusCode: http.StatusTeapot, }, @@ -631,7 +631,7 @@ func TestRedirectFollowingHTTPClient(t *testing.T) { checkRedirect: func(int) error { return ErrTooManyRedirects }, client: &multiStaticHTTPClient{ responses: []staticHTTPResponse{ - staticHTTPResponse{ + { resp: http.Response{ StatusCode: http.StatusTemporaryRedirect, }, @@ -646,7 +646,7 @@ func TestRedirectFollowingHTTPClient(t *testing.T) { checkRedirect: func(int) error { return ErrTooManyRedirects }, client: &multiStaticHTTPClient{ responses: []staticHTTPResponse{ - staticHTTPResponse{ + { resp: http.Response{ StatusCode: http.StatusTemporaryRedirect, Header: http.Header{"Location": []string{":"}}, @@ -714,7 +714,7 @@ func TestDefaultCheckRedirect(t *testing.T) { func TestHTTPClusterClientSync(t *testing.T) { cf := newStaticHTTPClientFactory([]staticHTTPResponse{ - staticHTTPResponse{ + { resp: http.Response{StatusCode: http.StatusOK, Header: http.Header{"Content-Type": []string{"application/json"}}}, body: []byte(`{"members":[{"id":"2745e2525fce8fe","peerURLs":["http://127.0.0.1:7003"],"name":"node3","clientURLs":["http://127.0.0.1:4003"]},{"id":"42134f434382925","peerURLs":["http://127.0.0.1:2380","http://127.0.0.1:7001"],"name":"node1","clientURLs":["http://127.0.0.1:2379","http://127.0.0.1:4001"]},{"id":"94088180e21eb87b","peerURLs":["http://127.0.0.1:7002"],"name":"node2","clientURLs":["http://127.0.0.1:4002"]}]}`), }, @@ -761,7 +761,7 @@ func TestHTTPClusterClientSync(t *testing.T) { func TestHTTPClusterClientSyncFail(t *testing.T) { cf := newStaticHTTPClientFactory([]staticHTTPResponse{ - staticHTTPResponse{err: errors.New("fail!")}, + {err: errors.New("fail!")}, }) hc := &httpClusterClient{ @@ -792,7 +792,7 @@ func TestHTTPClusterClientSyncFail(t *testing.T) { func TestHTTPClusterClientAutoSyncCancelContext(t *testing.T) { cf := newStaticHTTPClientFactory([]staticHTTPResponse{ - staticHTTPResponse{ + { resp: http.Response{StatusCode: http.StatusOK, Header: http.Header{"Content-Type": []string{"application/json"}}}, body: []byte(`{"members":[{"id":"2745e2525fce8fe","peerURLs":["http://127.0.0.1:7003"],"name":"node3","clientURLs":["http://127.0.0.1:4003"]},{"id":"42134f434382925","peerURLs":["http://127.0.0.1:2380","http://127.0.0.1:7001"],"name":"node1","clientURLs":["http://127.0.0.1:2379","http://127.0.0.1:4001"]},{"id":"94088180e21eb87b","peerURLs":["http://127.0.0.1:7002"],"name":"node2","clientURLs":["http://127.0.0.1:4002"]}]}`), }, @@ -817,7 +817,7 @@ func TestHTTPClusterClientAutoSyncCancelContext(t *testing.T) { func TestHTTPClusterClientAutoSyncFail(t *testing.T) { cf := newStaticHTTPClientFactory([]staticHTTPResponse{ - staticHTTPResponse{err: errors.New("fail!")}, + {err: errors.New("fail!")}, }) hc := &httpClusterClient{ @@ -839,15 +839,15 @@ func TestHTTPClusterClientAutoSyncFail(t *testing.T) { // it gets the exactly same member list as before. func TestHTTPClusterClientSyncPinEndpoint(t *testing.T) { cf := newStaticHTTPClientFactory([]staticHTTPResponse{ - staticHTTPResponse{ + { resp: http.Response{StatusCode: http.StatusOK, Header: http.Header{"Content-Type": []string{"application/json"}}}, body: []byte(`{"members":[{"id":"2745e2525fce8fe","peerURLs":["http://127.0.0.1:7003"],"name":"node3","clientURLs":["http://127.0.0.1:4003"]},{"id":"42134f434382925","peerURLs":["http://127.0.0.1:2380","http://127.0.0.1:7001"],"name":"node1","clientURLs":["http://127.0.0.1:2379","http://127.0.0.1:4001"]},{"id":"94088180e21eb87b","peerURLs":["http://127.0.0.1:7002"],"name":"node2","clientURLs":["http://127.0.0.1:4002"]}]}`), }, - staticHTTPResponse{ + { resp: http.Response{StatusCode: http.StatusOK, Header: http.Header{"Content-Type": []string{"application/json"}}}, body: []byte(`{"members":[{"id":"2745e2525fce8fe","peerURLs":["http://127.0.0.1:7003"],"name":"node3","clientURLs":["http://127.0.0.1:4003"]},{"id":"42134f434382925","peerURLs":["http://127.0.0.1:2380","http://127.0.0.1:7001"],"name":"node1","clientURLs":["http://127.0.0.1:2379","http://127.0.0.1:4001"]},{"id":"94088180e21eb87b","peerURLs":["http://127.0.0.1:7002"],"name":"node2","clientURLs":["http://127.0.0.1:4002"]}]}`), }, - staticHTTPResponse{ + { resp: http.Response{StatusCode: http.StatusOK, Header: http.Header{"Content-Type": []string{"application/json"}}}, body: []byte(`{"members":[{"id":"2745e2525fce8fe","peerURLs":["http://127.0.0.1:7003"],"name":"node3","clientURLs":["http://127.0.0.1:4003"]},{"id":"42134f434382925","peerURLs":["http://127.0.0.1:2380","http://127.0.0.1:7001"],"name":"node1","clientURLs":["http://127.0.0.1:2379","http://127.0.0.1:4001"]},{"id":"94088180e21eb87b","peerURLs":["http://127.0.0.1:7002"],"name":"node2","clientURLs":["http://127.0.0.1:4002"]}]}`), }, @@ -878,10 +878,10 @@ func TestHTTPClusterClientSyncPinEndpoint(t *testing.T) { func TestHTTPClusterClientResetFail(t *testing.T) { tests := [][]string{ // need at least one endpoint - []string{}, + {}, // urls must be valid - []string{":"}, + {":"}, } for i, tt := range tests { diff --git a/client/keys_test.go b/client/keys_test.go index 58a0ef115..cafe6bea4 100644 --- a/client/keys_test.go +++ b/client/keys_test.go @@ -221,7 +221,7 @@ func TestWaitAction(t *testing.T) { func TestSetAction(t *testing.T) { wantHeader := http.Header(map[string][]string{ - "Content-Type": []string{"application/x-www-form-urlencoded"}, + "Content-Type": {"application/x-www-form-urlencoded"}, }) tests := []struct { @@ -412,7 +412,7 @@ func TestSetAction(t *testing.T) { func TestCreateInOrderAction(t *testing.T) { wantHeader := http.Header(map[string][]string{ - "Content-Type": []string{"application/x-www-form-urlencoded"}, + "Content-Type": {"application/x-www-form-urlencoded"}, }) tests := []struct { @@ -513,7 +513,7 @@ func TestCreateInOrderAction(t *testing.T) { func TestDeleteAction(t *testing.T) { wantHeader := http.Header(map[string][]string{ - "Content-Type": []string{"application/x-www-form-urlencoded"}, + "Content-Type": {"application/x-www-form-urlencoded"}, }) tests := []struct { @@ -1213,7 +1213,7 @@ func TestHTTPKeysAPIGetResponse(t *testing.T) { Node: &Node{ Key: "/pants/foo/bar", Nodes: []*Node{ - &Node{Key: "/pants/foo/bar/baz", Value: "snarf", CreatedIndex: 21, ModifiedIndex: 25}, + {Key: "/pants/foo/bar/baz", Value: "snarf", CreatedIndex: 21, ModifiedIndex: 25}, }, CreatedIndex: uint64(19), ModifiedIndex: uint64(25), diff --git a/client/members_test.go b/client/members_test.go index eb0a36eb8..df7be1ccb 100644 --- a/client/members_test.go +++ b/client/members_test.go @@ -48,8 +48,8 @@ func TestMembersAPIActionAdd(t *testing.T) { ep := url.URL{Scheme: "http", Host: "example.com"} act := &membersAPIActionAdd{ peerURLs: types.URLs([]url.URL{ - url.URL{Scheme: "https", Host: "127.0.0.1:8081"}, - url.URL{Scheme: "http", Host: "127.0.0.1:8080"}, + {Scheme: "https", Host: "127.0.0.1:8081"}, + {Scheme: "http", Host: "127.0.0.1:8080"}, }), } @@ -75,8 +75,8 @@ func TestMembersAPIActionUpdate(t *testing.T) { act := &membersAPIActionUpdate{ memberID: "0xabcd", peerURLs: types.URLs([]url.URL{ - url.URL{Scheme: "https", Host: "127.0.0.1:8081"}, - url.URL{Scheme: "http", Host: "127.0.0.1:8080"}, + {Scheme: "https", Host: "127.0.0.1:8081"}, + {Scheme: "http", Host: "127.0.0.1:8080"}, }), } @@ -289,8 +289,8 @@ func TestMemberCollectionUnmarshal(t *testing.T) { func TestMemberCreateRequestMarshal(t *testing.T) { req := memberCreateOrUpdateRequest{ PeerURLs: types.URLs([]url.URL{ - url.URL{Scheme: "http", Host: "127.0.0.1:8081"}, - url.URL{Scheme: "https", Host: "127.0.0.1:8080"}, + {Scheme: "http", Host: "127.0.0.1:8081"}, + {Scheme: "https", Host: "127.0.0.1:8080"}, }), } want := []byte(`{"peerURLs":["http://127.0.0.1:8081","https://127.0.0.1:8080"]}`) @@ -308,7 +308,7 @@ func TestMemberCreateRequestMarshal(t *testing.T) { func TestHTTPMembersAPIAddSuccess(t *testing.T) { wantAction := &membersAPIActionAdd{ peerURLs: types.URLs([]url.URL{ - url.URL{Scheme: "http", Host: "127.0.0.1:7002"}, + {Scheme: "http", Host: "127.0.0.1:7002"}, }), } @@ -473,7 +473,7 @@ func TestHTTPMembersAPIListSuccess(t *testing.T) { } wantResponseMembers := []Member{ - Member{ + { ID: "94088180e21eb87b", Name: "node2", PeerURLs: []string{"http://127.0.0.1:7002"}, diff --git a/client/srv_test.go b/client/srv_test.go index 72b1c9a46..a4a27f108 100644 --- a/client/srv_test.go +++ b/client/srv_test.go @@ -36,40 +36,40 @@ func TestSRVDiscover(t *testing.T) { }, { []*net.SRV{ - &net.SRV{Target: "10.0.0.1", Port: 2480}, - &net.SRV{Target: "10.0.0.2", Port: 2480}, - &net.SRV{Target: "10.0.0.3", Port: 2480}, + {Target: "10.0.0.1", Port: 2480}, + {Target: "10.0.0.2", Port: 2480}, + {Target: "10.0.0.3", Port: 2480}, }, []*net.SRV{}, []string{"https://10.0.0.1:2480", "https://10.0.0.2:2480", "https://10.0.0.3:2480"}, }, { []*net.SRV{ - &net.SRV{Target: "10.0.0.1", Port: 2480}, - &net.SRV{Target: "10.0.0.2", Port: 2480}, - &net.SRV{Target: "10.0.0.3", Port: 2480}, + {Target: "10.0.0.1", Port: 2480}, + {Target: "10.0.0.2", Port: 2480}, + {Target: "10.0.0.3", Port: 2480}, }, []*net.SRV{ - &net.SRV{Target: "10.0.0.1", Port: 7001}, + {Target: "10.0.0.1", Port: 7001}, }, []string{"https://10.0.0.1:2480", "https://10.0.0.2:2480", "https://10.0.0.3:2480", "http://10.0.0.1:7001"}, }, { []*net.SRV{ - &net.SRV{Target: "10.0.0.1", Port: 2480}, - &net.SRV{Target: "10.0.0.2", Port: 2480}, - &net.SRV{Target: "10.0.0.3", Port: 2480}, + {Target: "10.0.0.1", Port: 2480}, + {Target: "10.0.0.2", Port: 2480}, + {Target: "10.0.0.3", Port: 2480}, }, []*net.SRV{ - &net.SRV{Target: "10.0.0.1", Port: 7001}, + {Target: "10.0.0.1", Port: 7001}, }, []string{"https://10.0.0.1:2480", "https://10.0.0.2:2480", "https://10.0.0.3:2480", "http://10.0.0.1:7001"}, }, { []*net.SRV{ - &net.SRV{Target: "a.example.com", Port: 2480}, - &net.SRV{Target: "b.example.com", Port: 2480}, - &net.SRV{Target: "c.example.com", Port: 2480}, + {Target: "a.example.com", Port: 2480}, + {Target: "b.example.com", Port: 2480}, + {Target: "c.example.com", Port: 2480}, }, []*net.SRV{}, []string{"https://a.example.com:2480", "https://b.example.com:2480", "https://c.example.com:2480"}, diff --git a/discovery/srv_test.go b/discovery/srv_test.go index de44682fd..f61aae414 100644 --- a/discovery/srv_test.go +++ b/discovery/srv_test.go @@ -47,9 +47,9 @@ func TestSRVGetCluster(t *testing.T) { }, { []*net.SRV{ - &net.SRV{Target: "10.0.0.1", Port: 2480}, - &net.SRV{Target: "10.0.0.2", Port: 2480}, - &net.SRV{Target: "10.0.0.3", Port: 2480}, + {Target: "10.0.0.1", Port: 2480}, + {Target: "10.0.0.2", Port: 2480}, + {Target: "10.0.0.3", Port: 2480}, }, []*net.SRV{}, nil, @@ -59,12 +59,12 @@ func TestSRVGetCluster(t *testing.T) { }, { []*net.SRV{ - &net.SRV{Target: "10.0.0.1", Port: 2480}, - &net.SRV{Target: "10.0.0.2", Port: 2480}, - &net.SRV{Target: "10.0.0.3", Port: 2480}, + {Target: "10.0.0.1", Port: 2480}, + {Target: "10.0.0.2", Port: 2480}, + {Target: "10.0.0.3", Port: 2480}, }, []*net.SRV{ - &net.SRV{Target: "10.0.0.1", Port: 2380}, + {Target: "10.0.0.1", Port: 2380}, }, nil, nil, @@ -72,12 +72,12 @@ func TestSRVGetCluster(t *testing.T) { }, { []*net.SRV{ - &net.SRV{Target: "10.0.0.1", Port: 2480}, - &net.SRV{Target: "10.0.0.2", Port: 2480}, - &net.SRV{Target: "10.0.0.3", Port: 2480}, + {Target: "10.0.0.1", Port: 2480}, + {Target: "10.0.0.2", Port: 2480}, + {Target: "10.0.0.3", Port: 2480}, }, []*net.SRV{ - &net.SRV{Target: "10.0.0.1", Port: 2380}, + {Target: "10.0.0.1", Port: 2380}, }, []string{"https://10.0.0.1:2480"}, nil, @@ -86,9 +86,9 @@ func TestSRVGetCluster(t *testing.T) { // matching local member with resolved addr and return unresolved hostnames { []*net.SRV{ - &net.SRV{Target: "1.example.com.", Port: 2480}, - &net.SRV{Target: "2.example.com.", Port: 2480}, - &net.SRV{Target: "3.example.com.", Port: 2480}, + {Target: "1.example.com.", Port: 2480}, + {Target: "2.example.com.", Port: 2480}, + {Target: "3.example.com.", Port: 2480}, }, nil, []string{"https://10.0.0.1:2480"}, diff --git a/error/error_test.go b/error/error_test.go index 2a8fa32e1..1fdfacb75 100644 --- a/error/error_test.go +++ b/error/error_test.go @@ -23,7 +23,7 @@ import ( ) func TestErrorWriteTo(t *testing.T) { - for k, _ := range errors { + for k := range errors { err := NewError(k, "", 1) rr := httptest.NewRecorder() err.WriteTo(rr) @@ -38,8 +38,8 @@ func TestErrorWriteTo(t *testing.T) { } wheader := http.Header(map[string][]string{ - "Content-Type": []string{"application/json"}, - "X-Etcd-Index": []string{"1"}, + "Content-Type": {"application/json"}, + "X-Etcd-Index": {"1"}, }) if !reflect.DeepEqual(wheader, rr.HeaderMap) { diff --git a/etcdctl/command/auth_commands.go b/etcdctl/command/auth_commands.go index 8b72fc937..2ee483fab 100644 --- a/etcdctl/command/auth_commands.go +++ b/etcdctl/command/auth_commands.go @@ -29,12 +29,12 @@ func NewAuthCommands() cli.Command { Name: "auth", Usage: "overall auth controls", Subcommands: []cli.Command{ - cli.Command{ + { Name: "enable", Usage: "enable auth access controls", Action: actionAuthEnable, }, - cli.Command{ + { Name: "disable", Usage: "disable auth access controls", Action: actionAuthDisable, diff --git a/etcdctl/command/member_commands.go b/etcdctl/command/member_commands.go index def168099..be59886bd 100644 --- a/etcdctl/command/member_commands.go +++ b/etcdctl/command/member_commands.go @@ -29,22 +29,22 @@ func NewMemberCommand() cli.Command { Name: "member", Usage: "member add, remove and list subcommands", Subcommands: []cli.Command{ - cli.Command{ + { Name: "list", Usage: "enumerate existing cluster members", Action: actionMemberList, }, - cli.Command{ + { Name: "add", Usage: "add a new member to the etcd cluster", Action: actionMemberAdd, }, - cli.Command{ + { Name: "remove", Usage: "remove an existing member from the etcd cluster", Action: actionMemberRemove, }, - cli.Command{ + { Name: "update", Usage: "update an existing member in the etcd cluster", Action: actionMemberUpdate, diff --git a/etcdctl/command/role_commands.go b/etcdctl/command/role_commands.go index 96777886d..2b3ed2401 100644 --- a/etcdctl/command/role_commands.go +++ b/etcdctl/command/role_commands.go @@ -31,27 +31,27 @@ func NewRoleCommands() cli.Command { Name: "role", Usage: "role add, grant and revoke subcommands", Subcommands: []cli.Command{ - cli.Command{ + { Name: "add", Usage: "add a new role for the etcd cluster", Action: actionRoleAdd, }, - cli.Command{ + { Name: "get", Usage: "get details for a role", Action: actionRoleGet, }, - cli.Command{ + { Name: "list", Usage: "list all roles", Action: actionRoleList, }, - cli.Command{ + { Name: "remove", Usage: "remove a role from the etcd cluster", Action: actionRoleRemove, }, - cli.Command{ + { Name: "grant", Usage: "grant path matches to an etcd role", Flags: []cli.Flag{ @@ -62,7 +62,7 @@ func NewRoleCommands() cli.Command { }, Action: actionRoleGrant, }, - cli.Command{ + { Name: "revoke", Usage: "revoke path matches for an etcd role", Flags: []cli.Flag{ diff --git a/etcdctl/command/user_commands.go b/etcdctl/command/user_commands.go index ace215f8c..5596fe78b 100644 --- a/etcdctl/command/user_commands.go +++ b/etcdctl/command/user_commands.go @@ -32,39 +32,39 @@ func NewUserCommands() cli.Command { Name: "user", Usage: "user add, grant and revoke subcommands", Subcommands: []cli.Command{ - cli.Command{ + { Name: "add", Usage: "add a new user for the etcd cluster", Action: actionUserAdd, }, - cli.Command{ + { Name: "get", Usage: "get details for a user", Action: actionUserGet, }, - cli.Command{ + { Name: "list", Usage: "list all current users", Action: actionUserList, }, - cli.Command{ + { Name: "remove", Usage: "remove a user for the etcd cluster", Action: actionUserRemove, }, - cli.Command{ + { Name: "grant", Usage: "grant roles to an etcd user", Flags: []cli.Flag{cli.StringSliceFlag{Name: "roles", Value: new(cli.StringSlice), Usage: "List of roles to grant or revoke"}}, Action: actionUserGrant, }, - cli.Command{ + { Name: "revoke", Usage: "revoke roles for an etcd user", Flags: []cli.Flag{cli.StringSliceFlag{Name: "roles", Value: new(cli.StringSlice), Usage: "List of roles to grant or revoke"}}, Action: actionUserRevoke, }, - cli.Command{ + { Name: "passwd", Usage: "change password for a user", Action: actionUserPasswd, diff --git a/etcdmain/config_test.go b/etcdmain/config_test.go index b2bb9cc4b..9f7b7444b 100644 --- a/etcdmain/config_test.go +++ b/etcdmain/config_test.go @@ -184,19 +184,19 @@ func TestConfigParsingV1Flags(t *testing.T) { func TestConfigParsingConflictClusteringFlags(t *testing.T) { conflictArgs := [][]string{ - []string{ + { "-initial-cluster=0=localhost:8000", "-discovery=http://example.com/abc", }, - []string{ + { "-discovery-srv=example.com", "-discovery=http://example.com/abc", }, - []string{ + { "-initial-cluster=0=localhost:8000", "-discovery-srv=example.com", }, - []string{ + { "-initial-cluster=0=localhost:8000", "-discovery=http://example.com/abc", "-discovery-srv=example.com", diff --git a/etcdserver/auth/auth_test.go b/etcdserver/auth/auth_test.go index 704e56ddf..11acd05ba 100644 --- a/etcdserver/auth/auth_test.go +++ b/etcdserver/auth/auth_test.go @@ -196,10 +196,10 @@ func TestAllUsers(t *testing.T) { Action: etcdstore.Get, Node: &etcdstore.NodeExtern{ Nodes: etcdstore.NodeExterns([]*etcdstore.NodeExtern{ - &etcdstore.NodeExtern{ + { Key: StorePermsPrefix + "/users/cat", }, - &etcdstore.NodeExtern{ + { Key: StorePermsPrefix + "/users/dog", }, }), @@ -260,10 +260,10 @@ func TestAllRoles(t *testing.T) { Action: etcdstore.Get, Node: &etcdstore.NodeExtern{ Nodes: etcdstore.NodeExterns([]*etcdstore.NodeExtern{ - &etcdstore.NodeExtern{ + { Key: StorePermsPrefix + "/roles/animal", }, - &etcdstore.NodeExtern{ + { Key: StorePermsPrefix + "/roles/human", }, }), diff --git a/etcdserver/cluster.go b/etcdserver/cluster.go index 23737de70..bf4917d5f 100644 --- a/etcdserver/cluster.go +++ b/etcdserver/cluster.go @@ -198,7 +198,7 @@ func (c *cluster) String() string { } fmt.Fprintf(b, "Members:[%s] ", strings.Join(ms, " ")) var ids []string - for id, _ := range c.removed { + for id := range c.removed { ids = append(ids, fmt.Sprintf("%s", id)) } fmt.Fprintf(b, "RemovedMemberIDs:[%s]}", strings.Join(ids, " ")) diff --git a/etcdserver/cluster_test.go b/etcdserver/cluster_test.go index fe5af2afb..fa571e10d 100644 --- a/etcdserver/cluster_test.go +++ b/etcdserver/cluster_test.go @@ -472,19 +472,19 @@ func TestClusterAddMember(t *testing.T) { func TestClusterMembers(t *testing.T) { cls := &cluster{ members: map[types.ID]*Member{ - 1: &Member{ID: 1}, - 20: &Member{ID: 20}, - 100: &Member{ID: 100}, - 5: &Member{ID: 5}, - 50: &Member{ID: 50}, + 1: {ID: 1}, + 20: {ID: 20}, + 100: {ID: 100}, + 5: {ID: 5}, + 50: {ID: 50}, }, } w := []*Member{ - &Member{ID: 1}, - &Member{ID: 5}, - &Member{ID: 20}, - &Member{ID: 50}, - &Member{ID: 100}, + {ID: 1}, + {ID: 5}, + {ID: 20}, + {ID: 50}, + {ID: 100}, } if g := cls.Members(); !reflect.DeepEqual(g, w) { t.Fatalf("Members()=%#v, want %#v", g, w) diff --git a/etcdserver/cluster_util_test.go b/etcdserver/cluster_util_test.go index 1409255f5..e602bddad 100644 --- a/etcdserver/cluster_util_test.go +++ b/etcdserver/cluster_util_test.go @@ -29,7 +29,7 @@ func TestDecideClusterVersion(t *testing.T) { wdver *semver.Version }{ { - map[string]*version.Versions{"a": &version.Versions{Server: "2.0.0"}}, + map[string]*version.Versions{"a": {Server: "2.0.0"}}, semver.Must(semver.NewVersion("2.0.0")), }, // unknow @@ -38,15 +38,15 @@ func TestDecideClusterVersion(t *testing.T) { nil, }, { - map[string]*version.Versions{"a": &version.Versions{Server: "2.0.0"}, "b": &version.Versions{Server: "2.1.0"}, "c": &version.Versions{Server: "2.1.0"}}, + map[string]*version.Versions{"a": {Server: "2.0.0"}, "b": {Server: "2.1.0"}, "c": {Server: "2.1.0"}}, semver.Must(semver.NewVersion("2.0.0")), }, { - map[string]*version.Versions{"a": &version.Versions{Server: "2.1.0"}, "b": &version.Versions{Server: "2.1.0"}, "c": &version.Versions{Server: "2.1.0"}}, + map[string]*version.Versions{"a": {Server: "2.1.0"}, "b": {Server: "2.1.0"}, "c": {Server: "2.1.0"}}, semver.Must(semver.NewVersion("2.1.0")), }, { - map[string]*version.Versions{"a": nil, "b": &version.Versions{Server: "2.1.0"}, "c": &version.Versions{Server: "2.1.0"}}, + map[string]*version.Versions{"a": nil, "b": {Server: "2.1.0"}, "c": {Server: "2.1.0"}}, nil, }, } @@ -69,9 +69,9 @@ func TestIsCompatibleWithVers(t *testing.T) { // too low { map[string]*version.Versions{ - "a": &version.Versions{Server: "2.0.0", Cluster: "not_decided"}, - "b": &version.Versions{Server: "2.1.0", Cluster: "2.1.0"}, - "c": &version.Versions{Server: "2.1.0", Cluster: "2.1.0"}, + "a": {Server: "2.0.0", Cluster: "not_decided"}, + "b": {Server: "2.1.0", Cluster: "2.1.0"}, + "c": {Server: "2.1.0", Cluster: "2.1.0"}, }, 0xa, semver.Must(semver.NewVersion("2.0.0")), semver.Must(semver.NewVersion("2.0.0")), @@ -79,9 +79,9 @@ func TestIsCompatibleWithVers(t *testing.T) { }, { map[string]*version.Versions{ - "a": &version.Versions{Server: "2.1.0", Cluster: "not_decided"}, - "b": &version.Versions{Server: "2.1.0", Cluster: "2.1.0"}, - "c": &version.Versions{Server: "2.1.0", Cluster: "2.1.0"}, + "a": {Server: "2.1.0", Cluster: "not_decided"}, + "b": {Server: "2.1.0", Cluster: "2.1.0"}, + "c": {Server: "2.1.0", Cluster: "2.1.0"}, }, 0xa, semver.Must(semver.NewVersion("2.0.0")), semver.Must(semver.NewVersion("2.1.0")), @@ -90,9 +90,9 @@ func TestIsCompatibleWithVers(t *testing.T) { // too high { map[string]*version.Versions{ - "a": &version.Versions{Server: "2.2.0", Cluster: "not_decided"}, - "b": &version.Versions{Server: "2.0.0", Cluster: "2.0.0"}, - "c": &version.Versions{Server: "2.0.0", Cluster: "2.0.0"}, + "a": {Server: "2.2.0", Cluster: "not_decided"}, + "b": {Server: "2.0.0", Cluster: "2.0.0"}, + "c": {Server: "2.0.0", Cluster: "2.0.0"}, }, 0xa, semver.Must(semver.NewVersion("2.1.0")), semver.Must(semver.NewVersion("2.2.0")), @@ -101,9 +101,9 @@ func TestIsCompatibleWithVers(t *testing.T) { // cannot get b's version, expect ok { map[string]*version.Versions{ - "a": &version.Versions{Server: "2.1.0", Cluster: "not_decided"}, + "a": {Server: "2.1.0", Cluster: "not_decided"}, "b": nil, - "c": &version.Versions{Server: "2.1.0", Cluster: "2.1.0"}, + "c": {Server: "2.1.0", Cluster: "2.1.0"}, }, 0xa, semver.Must(semver.NewVersion("2.0.0")), semver.Must(semver.NewVersion("2.1.0")), @@ -112,7 +112,7 @@ func TestIsCompatibleWithVers(t *testing.T) { // cannot get b and c's version, expect not ok { map[string]*version.Versions{ - "a": &version.Versions{Server: "2.1.0", Cluster: "not_decided"}, + "a": {Server: "2.1.0", Cluster: "not_decided"}, "b": nil, "c": nil, }, diff --git a/etcdserver/etcdhttp/client_test.go b/etcdserver/etcdhttp/client_test.go index 7e4013a5b..c048bb42b 100644 --- a/etcdserver/etcdhttp/client_test.go +++ b/etcdserver/etcdhttp/client_test.go @@ -817,7 +817,7 @@ func TestServeMembersFail(t *testing.T) { URL: testutil.MustNewURL(t, membersPrefix), Method: "POST", Body: ioutil.NopCloser(strings.NewReader("bad json")), - Header: map[string][]string{"Content-Type": []string{"application/json"}}, + Header: map[string][]string{"Content-Type": {"application/json"}}, }, &resServer{}, @@ -829,7 +829,7 @@ func TestServeMembersFail(t *testing.T) { URL: testutil.MustNewURL(t, membersPrefix), Method: "POST", Body: ioutil.NopCloser(strings.NewReader(`{"PeerURLs": ["http://127.0.0.1:1"]}`)), - Header: map[string][]string{"Content-Type": []string{"application/bad"}}, + Header: map[string][]string{"Content-Type": {"application/bad"}}, }, &errServer{}, @@ -841,7 +841,7 @@ func TestServeMembersFail(t *testing.T) { URL: testutil.MustNewURL(t, membersPrefix), Method: "POST", Body: ioutil.NopCloser(strings.NewReader(`{"PeerURLs": ["http://a"]}`)), - Header: map[string][]string{"Content-Type": []string{"application/json"}}, + Header: map[string][]string{"Content-Type": {"application/json"}}, }, &errServer{}, @@ -853,7 +853,7 @@ func TestServeMembersFail(t *testing.T) { URL: testutil.MustNewURL(t, membersPrefix), Method: "POST", Body: ioutil.NopCloser(strings.NewReader(`{"PeerURLs": ["http://127.0.0.1:1"]}`)), - Header: map[string][]string{"Content-Type": []string{"application/json"}}, + Header: map[string][]string{"Content-Type": {"application/json"}}, }, &errServer{ errors.New("Error while adding a member"), @@ -867,7 +867,7 @@ func TestServeMembersFail(t *testing.T) { URL: testutil.MustNewURL(t, membersPrefix), Method: "POST", Body: ioutil.NopCloser(strings.NewReader(`{"PeerURLs": ["http://127.0.0.1:1"]}`)), - Header: map[string][]string{"Content-Type": []string{"application/json"}}, + Header: map[string][]string{"Content-Type": {"application/json"}}, }, &errServer{ etcdserver.ErrIDExists, @@ -881,7 +881,7 @@ func TestServeMembersFail(t *testing.T) { URL: testutil.MustNewURL(t, membersPrefix), Method: "POST", Body: ioutil.NopCloser(strings.NewReader(`{"PeerURLs": ["http://127.0.0.1:1"]}`)), - Header: map[string][]string{"Content-Type": []string{"application/json"}}, + Header: map[string][]string{"Content-Type": {"application/json"}}, }, &errServer{ etcdserver.ErrPeerURLexists, @@ -951,7 +951,7 @@ func TestServeMembersFail(t *testing.T) { URL: testutil.MustNewURL(t, path.Join(membersPrefix, "0")), Method: "PUT", Body: ioutil.NopCloser(strings.NewReader("bad json")), - Header: map[string][]string{"Content-Type": []string{"application/json"}}, + Header: map[string][]string{"Content-Type": {"application/json"}}, }, &resServer{}, @@ -963,7 +963,7 @@ func TestServeMembersFail(t *testing.T) { URL: testutil.MustNewURL(t, path.Join(membersPrefix, "0")), Method: "PUT", Body: ioutil.NopCloser(strings.NewReader(`{"PeerURLs": ["http://127.0.0.1:1"]}`)), - Header: map[string][]string{"Content-Type": []string{"application/bad"}}, + Header: map[string][]string{"Content-Type": {"application/bad"}}, }, &errServer{}, @@ -975,7 +975,7 @@ func TestServeMembersFail(t *testing.T) { URL: testutil.MustNewURL(t, path.Join(membersPrefix, "0")), Method: "PUT", Body: ioutil.NopCloser(strings.NewReader(`{"PeerURLs": ["http://a"]}`)), - Header: map[string][]string{"Content-Type": []string{"application/json"}}, + Header: map[string][]string{"Content-Type": {"application/json"}}, }, &errServer{}, @@ -987,7 +987,7 @@ func TestServeMembersFail(t *testing.T) { URL: testutil.MustNewURL(t, path.Join(membersPrefix, "0")), Method: "PUT", Body: ioutil.NopCloser(strings.NewReader(`{"PeerURLs": ["http://127.0.0.1:1"]}`)), - Header: map[string][]string{"Content-Type": []string{"application/json"}}, + Header: map[string][]string{"Content-Type": {"application/json"}}, }, &errServer{ errors.New("blah"), @@ -1001,7 +1001,7 @@ func TestServeMembersFail(t *testing.T) { URL: testutil.MustNewURL(t, path.Join(membersPrefix, "0")), Method: "PUT", Body: ioutil.NopCloser(strings.NewReader(`{"PeerURLs": ["http://127.0.0.1:1"]}`)), - Header: map[string][]string{"Content-Type": []string{"application/json"}}, + Header: map[string][]string{"Content-Type": {"application/json"}}, }, &errServer{ etcdserver.ErrPeerURLexists, @@ -1015,7 +1015,7 @@ func TestServeMembersFail(t *testing.T) { URL: testutil.MustNewURL(t, path.Join(membersPrefix, "0")), Method: "PUT", Body: ioutil.NopCloser(strings.NewReader(`{"PeerURLs": ["http://127.0.0.1:1"]}`)), - Header: map[string][]string{"Content-Type": []string{"application/json"}}, + Header: map[string][]string{"Content-Type": {"application/json"}}, }, &errServer{ etcdserver.ErrIDNotFound, @@ -1918,12 +1918,12 @@ func TestTrimPrefix(t *testing.T) { func TestNewMemberCollection(t *testing.T) { fixture := []*etcdserver.Member{ - &etcdserver.Member{ + { ID: 12, Attributes: etcdserver.Attributes{ClientURLs: []string{"http://localhost:8080", "http://localhost:8081"}}, RaftAttributes: etcdserver.RaftAttributes{PeerURLs: []string{"http://localhost:8082", "http://localhost:8083"}}, }, - &etcdserver.Member{ + { ID: 13, Attributes: etcdserver.Attributes{ClientURLs: []string{"http://localhost:9090", "http://localhost:9091"}}, RaftAttributes: etcdserver.RaftAttributes{PeerURLs: []string{"http://localhost:9092", "http://localhost:9093"}}, @@ -1932,12 +1932,12 @@ func TestNewMemberCollection(t *testing.T) { got := newMemberCollection(fixture) want := httptypes.MemberCollection([]httptypes.Member{ - httptypes.Member{ + { ID: "c", ClientURLs: []string{"http://localhost:8080", "http://localhost:8081"}, PeerURLs: []string{"http://localhost:8082", "http://localhost:8083"}, }, - httptypes.Member{ + { ID: "d", ClientURLs: []string{"http://localhost:9090", "http://localhost:9091"}, PeerURLs: []string{"http://localhost:9092", "http://localhost:9093"}, diff --git a/etcdserver/etcdhttp/httptypes/errors_test.go b/etcdserver/etcdhttp/httptypes/errors_test.go index f5cec6d45..1f23c334b 100644 --- a/etcdserver/etcdhttp/httptypes/errors_test.go +++ b/etcdserver/etcdhttp/httptypes/errors_test.go @@ -28,7 +28,7 @@ func TestHTTPErrorWriteTo(t *testing.T) { wcode := http.StatusBadRequest wheader := http.Header(map[string][]string{ - "Content-Type": []string{"application/json"}, + "Content-Type": {"application/json"}, }) wbody := `{"message":"what a bad request you made!"}` diff --git a/etcdserver/etcdhttp/httptypes/member_test.go b/etcdserver/etcdhttp/httptypes/member_test.go index cfff78381..4ea4320c3 100644 --- a/etcdserver/etcdhttp/httptypes/member_test.go +++ b/etcdserver/etcdhttp/httptypes/member_test.go @@ -97,8 +97,8 @@ func TestMemberCreateRequestUnmarshal(t *testing.T) { body := []byte(`{"peerURLs": ["http://127.0.0.1:8081", "https://127.0.0.1:8080"]}`) want := MemberCreateRequest{ PeerURLs: types.URLs([]url.URL{ - url.URL{Scheme: "http", Host: "127.0.0.1:8081"}, - url.URL{Scheme: "https", Host: "127.0.0.1:8080"}, + {Scheme: "http", Host: "127.0.0.1:8081"}, + {Scheme: "https", Host: "127.0.0.1:8080"}, }), } diff --git a/etcdserver/server.go b/etcdserver/server.go index f99f33611..e3d0f20f6 100644 --- a/etcdserver/server.go +++ b/etcdserver/server.go @@ -722,7 +722,7 @@ func (s *EtcdServer) publish(timeout time.Duration) { } func (s *EtcdServer) send(ms []raftpb.Message) { - for i, _ := range ms { + for i := range ms { if s.cluster.IsIDRemoved(types.ID(ms[i].To)) { ms[i].To = 0 } diff --git a/etcdserver/server_test.go b/etcdserver/server_test.go index b6efaebb9..cba869f7f 100644 --- a/etcdserver/server_test.go +++ b/etcdserver/server_test.go @@ -509,10 +509,10 @@ func TestApplyConfChangeShouldStop(t *testing.T) { func TestDoProposal(t *testing.T) { tests := []pb.Request{ - pb.Request{Method: "POST", ID: 1}, - pb.Request{Method: "PUT", ID: 1}, - pb.Request{Method: "DELETE", ID: 1}, - pb.Request{Method: "GET", ID: 1, Quorum: true}, + {Method: "POST", ID: 1}, + {Method: "PUT", ID: 1}, + {Method: "DELETE", ID: 1}, + {Method: "GET", ID: 1, Quorum: true}, } for i, tt := range tests { st := &storeRecorder{} diff --git a/integration/cluster_test.go b/integration/cluster_test.go index ecb66da3c..ffc49cf26 100644 --- a/integration/cluster_test.go +++ b/integration/cluster_test.go @@ -417,7 +417,7 @@ func (c *cluster) Launch(t *testing.T) { errc <- m.Launch() }(m) } - for _ = range c.Members { + for range c.Members { if err := <-errc; err != nil { t.Fatalf("error setting up member: %v", err) } diff --git a/pkg/cors/cors.go b/pkg/cors/cors.go index 843bba465..7b509fb3f 100644 --- a/pkg/cors/cors.go +++ b/pkg/cors/cors.go @@ -45,7 +45,7 @@ func (ci *CORSInfo) Set(s string) error { func (ci *CORSInfo) String() string { o := make([]string, 0) - for k, _ := range *ci { + for k := range *ci { o = append(o, k) } return strings.Join(o, ",") diff --git a/pkg/flags/flag_test.go b/pkg/flags/flag_test.go index 3e3ca09c4..a44b7ad23 100644 --- a/pkg/flags/flag_test.go +++ b/pkg/flags/flag_test.go @@ -141,7 +141,7 @@ func TestURLsFromFlags(t *testing.T) { args: []string{}, tlsInfo: transport.TLSInfo{}, wantURLs: []url.URL{ - url.URL{Scheme: "http", Host: "127.0.0.1:2379"}, + {Scheme: "http", Host: "127.0.0.1:2379"}, }, wantFail: false, }, @@ -151,8 +151,8 @@ func TestURLsFromFlags(t *testing.T) { args: []string{"-urls=https://192.0.3.17:2930,http://127.0.0.1:1024"}, tlsInfo: transport.TLSInfo{}, wantURLs: []url.URL{ - url.URL{Scheme: "http", Host: "127.0.0.1:1024"}, - url.URL{Scheme: "https", Host: "192.0.3.17:2930"}, + {Scheme: "http", Host: "127.0.0.1:1024"}, + {Scheme: "https", Host: "192.0.3.17:2930"}, }, wantFail: false, }, @@ -162,7 +162,7 @@ func TestURLsFromFlags(t *testing.T) { args: []string{"-addr=192.0.2.3:1024"}, tlsInfo: transport.TLSInfo{}, wantURLs: []url.URL{ - url.URL{Scheme: "http", Host: "192.0.2.3:1024"}, + {Scheme: "http", Host: "192.0.2.3:1024"}, }, wantFail: false, }, @@ -175,7 +175,7 @@ func TestURLsFromFlags(t *testing.T) { KeyFile: "/tmp/bar", }, wantURLs: []url.URL{ - url.URL{Scheme: "https", Host: "192.0.2.3:1024"}, + {Scheme: "https", Host: "192.0.2.3:1024"}, }, wantFail: false, }, diff --git a/pkg/netutil/netutil_test.go b/pkg/netutil/netutil_test.go index 85bcf3cf1..65034af16 100644 --- a/pkg/netutil/netutil_test.go +++ b/pkg/netutil/netutil_test.go @@ -33,45 +33,45 @@ func TestResolveTCPAddrs(t *testing.T) { }{ { urls: [][]url.URL{ - []url.URL{ - url.URL{Scheme: "http", Host: "127.0.0.1:4001"}, - url.URL{Scheme: "http", Host: "127.0.0.1:2379"}, + { + {Scheme: "http", Host: "127.0.0.1:4001"}, + {Scheme: "http", Host: "127.0.0.1:2379"}, }, - []url.URL{ - url.URL{Scheme: "http", Host: "127.0.0.1:7001"}, - url.URL{Scheme: "http", Host: "127.0.0.1:2380"}, + { + {Scheme: "http", Host: "127.0.0.1:7001"}, + {Scheme: "http", Host: "127.0.0.1:2380"}, }, }, expected: [][]url.URL{ - []url.URL{ - url.URL{Scheme: "http", Host: "127.0.0.1:4001"}, - url.URL{Scheme: "http", Host: "127.0.0.1:2379"}, + { + {Scheme: "http", Host: "127.0.0.1:4001"}, + {Scheme: "http", Host: "127.0.0.1:2379"}, }, - []url.URL{ - url.URL{Scheme: "http", Host: "127.0.0.1:7001"}, - url.URL{Scheme: "http", Host: "127.0.0.1:2380"}, + { + {Scheme: "http", Host: "127.0.0.1:7001"}, + {Scheme: "http", Host: "127.0.0.1:2380"}, }, }, }, { urls: [][]url.URL{ - []url.URL{ - url.URL{Scheme: "http", Host: "infra0.example.com:4001"}, - url.URL{Scheme: "http", Host: "infra0.example.com:2379"}, + { + {Scheme: "http", Host: "infra0.example.com:4001"}, + {Scheme: "http", Host: "infra0.example.com:2379"}, }, - []url.URL{ - url.URL{Scheme: "http", Host: "infra0.example.com:7001"}, - url.URL{Scheme: "http", Host: "infra0.example.com:2380"}, + { + {Scheme: "http", Host: "infra0.example.com:7001"}, + {Scheme: "http", Host: "infra0.example.com:2380"}, }, }, expected: [][]url.URL{ - []url.URL{ - url.URL{Scheme: "http", Host: "10.0.1.10:4001"}, - url.URL{Scheme: "http", Host: "10.0.1.10:2379"}, + { + {Scheme: "http", Host: "10.0.1.10:4001"}, + {Scheme: "http", Host: "10.0.1.10:2379"}, }, - []url.URL{ - url.URL{Scheme: "http", Host: "10.0.1.10:7001"}, - url.URL{Scheme: "http", Host: "10.0.1.10:2380"}, + { + {Scheme: "http", Host: "10.0.1.10:7001"}, + {Scheme: "http", Host: "10.0.1.10:2380"}, }, }, hostMap: map[string]string{ @@ -81,13 +81,13 @@ func TestResolveTCPAddrs(t *testing.T) { }, { urls: [][]url.URL{ - []url.URL{ - url.URL{Scheme: "http", Host: "infra0.example.com:4001"}, - url.URL{Scheme: "http", Host: "infra0.example.com:2379"}, + { + {Scheme: "http", Host: "infra0.example.com:4001"}, + {Scheme: "http", Host: "infra0.example.com:2379"}, }, - []url.URL{ - url.URL{Scheme: "http", Host: "infra0.example.com:7001"}, - url.URL{Scheme: "http", Host: "infra0.example.com:2380"}, + { + {Scheme: "http", Host: "infra0.example.com:7001"}, + {Scheme: "http", Host: "infra0.example.com:2380"}, }, }, hostMap: map[string]string{ @@ -97,13 +97,13 @@ func TestResolveTCPAddrs(t *testing.T) { }, { urls: [][]url.URL{ - []url.URL{ - url.URL{Scheme: "http", Host: "ssh://infra0.example.com:4001"}, - url.URL{Scheme: "http", Host: "ssh://infra0.example.com:2379"}, + { + {Scheme: "http", Host: "ssh://infra0.example.com:4001"}, + {Scheme: "http", Host: "ssh://infra0.example.com:2379"}, }, - []url.URL{ - url.URL{Scheme: "http", Host: "ssh://infra0.example.com:7001"}, - url.URL{Scheme: "http", Host: "ssh://infra0.example.com:2380"}, + { + {Scheme: "http", Host: "ssh://infra0.example.com:7001"}, + {Scheme: "http", Host: "ssh://infra0.example.com:2380"}, }, }, hasError: true, diff --git a/pkg/transport/listener_test.go b/pkg/transport/listener_test.go index f6565e102..cee35ec5e 100644 --- a/pkg/transport/listener_test.go +++ b/pkg/transport/listener_test.go @@ -98,17 +98,17 @@ func TestNewTransportTLSInfo(t *testing.T) { defer os.Remove(tmp) tests := []TLSInfo{ - TLSInfo{}, - TLSInfo{ + {}, + { CertFile: tmp, KeyFile: tmp, }, - TLSInfo{ + { CertFile: tmp, KeyFile: tmp, CAFile: tmp, }, - TLSInfo{ + { CAFile: tmp, }, } @@ -157,10 +157,10 @@ func TestTLSInfoMissingFields(t *testing.T) { defer os.Remove(tmp) tests := []TLSInfo{ - TLSInfo{CertFile: tmp}, - TLSInfo{KeyFile: tmp}, - TLSInfo{CertFile: tmp, CAFile: tmp}, - TLSInfo{KeyFile: tmp, CAFile: tmp}, + {CertFile: tmp}, + {KeyFile: tmp}, + {CertFile: tmp, CAFile: tmp}, + {KeyFile: tmp, CAFile: tmp}, } for i, info := range tests { diff --git a/pkg/types/set.go b/pkg/types/set.go index 32287522b..bb997174c 100644 --- a/pkg/types/set.go +++ b/pkg/types/set.go @@ -91,7 +91,7 @@ func (us *unsafeSet) Length() int { // Values returns the values of the Set in an unspecified order. func (us *unsafeSet) Values() (values []string) { values = make([]string, 0) - for val, _ := range us.d { + for val := range us.d { values = append(values, val) } return @@ -100,7 +100,7 @@ func (us *unsafeSet) Values() (values []string) { // Copy creates a new Set containing the values of the first func (us *unsafeSet) Copy() Set { cp := NewUnsafeSet() - for val, _ := range us.d { + for val := range us.d { cp.Add(val) } diff --git a/proxy/director_test.go b/proxy/director_test.go index 0d56ea961..ac1c82a09 100644 --- a/proxy/director_test.go +++ b/proxy/director_test.go @@ -70,11 +70,11 @@ func TestNewDirectorScheme(t *testing.T) { func TestDirectorEndpointsFiltering(t *testing.T) { d := director{ ep: []*endpoint{ - &endpoint{ + { URL: url.URL{Scheme: "http", Host: "192.0.2.5:5050"}, Available: false, }, - &endpoint{ + { URL: url.URL{Scheme: "http", Host: "192.0.2.4:4000"}, Available: true, }, @@ -83,7 +83,7 @@ func TestDirectorEndpointsFiltering(t *testing.T) { got := d.endpoints() want := []*endpoint{ - &endpoint{ + { URL: url.URL{Scheme: "http", Host: "192.0.2.4:4000"}, Available: true, }, diff --git a/proxy/reverse_test.go b/proxy/reverse_test.go index 90824a575..01f5cfcd4 100644 --- a/proxy/reverse_test.go +++ b/proxy/reverse_test.go @@ -56,19 +56,19 @@ func TestReverseProxyServe(t *testing.T) { // error is returned from one endpoint that should be available { - eps: []*endpoint{&endpoint{URL: u, Available: true}}, + eps: []*endpoint{{URL: u, Available: true}}, rt: &staticRoundTripper{err: errors.New("what a bad trip")}, want: http.StatusBadGateway, }, // endpoint is available and returns success { - eps: []*endpoint{&endpoint{URL: u, Available: true}}, + eps: []*endpoint{{URL: u, Available: true}}, rt: &staticRoundTripper{ res: &http.Response{ StatusCode: http.StatusCreated, Body: ioutil.NopCloser(&bytes.Reader{}), - Header: map[string][]string{"Content-Type": []string{"application/json"}}, + Header: map[string][]string{"Content-Type": {"application/json"}}, }, }, want: http.StatusCreated, @@ -171,25 +171,25 @@ func TestMaybeSetForwardedFor(t *testing.T) { func TestRemoveSingleHopHeaders(t *testing.T) { hdr := http.Header(map[string][]string{ // single-hop headers that should be removed - "Connection": []string{"close"}, - "Keep-Alive": []string{"foo"}, - "Proxy-Authenticate": []string{"Basic realm=example.com"}, - "Proxy-Authorization": []string{"foo"}, - "Te": []string{"deflate,gzip"}, - "Trailers": []string{"ETag"}, - "Transfer-Encoding": []string{"chunked"}, - "Upgrade": []string{"WebSocket"}, + "Connection": {"close"}, + "Keep-Alive": {"foo"}, + "Proxy-Authenticate": {"Basic realm=example.com"}, + "Proxy-Authorization": {"foo"}, + "Te": {"deflate,gzip"}, + "Trailers": {"ETag"}, + "Transfer-Encoding": {"chunked"}, + "Upgrade": {"WebSocket"}, // headers that should persist - "Accept": []string{"application/json"}, - "X-Foo": []string{"Bar"}, + "Accept": {"application/json"}, + "X-Foo": {"Bar"}, }) removeSingleHopHeaders(&hdr) want := http.Header(map[string][]string{ - "Accept": []string{"application/json"}, - "X-Foo": []string{"Bar"}, + "Accept": {"application/json"}, + "X-Foo": {"Bar"}, }) if !reflect.DeepEqual(want, hdr) { @@ -205,33 +205,33 @@ func TestCopyHeader(t *testing.T) { }{ { src: http.Header(map[string][]string{ - "Foo": []string{"bar", "baz"}, + "Foo": {"bar", "baz"}, }), dst: http.Header(map[string][]string{}), want: http.Header(map[string][]string{ - "Foo": []string{"bar", "baz"}, + "Foo": {"bar", "baz"}, }), }, { src: http.Header(map[string][]string{ - "Foo": []string{"bar"}, - "Ping": []string{"pong"}, + "Foo": {"bar"}, + "Ping": {"pong"}, }), dst: http.Header(map[string][]string{}), want: http.Header(map[string][]string{ - "Foo": []string{"bar"}, - "Ping": []string{"pong"}, + "Foo": {"bar"}, + "Ping": {"pong"}, }), }, { src: http.Header(map[string][]string{ - "Foo": []string{"bar", "baz"}, + "Foo": {"bar", "baz"}, }), dst: http.Header(map[string][]string{ - "Foo": []string{"qux"}, + "Foo": {"qux"}, }), want: http.Header(map[string][]string{ - "Foo": []string{"qux", "bar", "baz"}, + "Foo": {"qux", "bar", "baz"}, }), }, } diff --git a/raft/raft_test.go b/raft/raft_test.go index dffdea6b2..7d148f8e3 100644 --- a/raft/raft_test.go +++ b/raft/raft_test.go @@ -480,7 +480,7 @@ func TestDuelingCandidates(t *testing.T) { nt.send(pb.Message{From: 3, To: 3, Type: pb.MsgHup}) wlog := &raftLog{ - storage: &MemoryStorage{ents: []pb.Entry{{}, pb.Entry{Data: nil, Term: 1, Index: 1}}}, + storage: &MemoryStorage{ents: []pb.Entry{{}, {Data: nil, Term: 1, Index: 1}}}, committed: 1, unstable: unstable{offset: 2}, } diff --git a/rafthttp/stream.go b/rafthttp/stream.go index 20d3597f7..5e9e8cdcd 100644 --- a/rafthttp/stream.go +++ b/rafthttp/stream.go @@ -46,9 +46,9 @@ var ( // the key is in string format "major.minor.patch" supportedStream = map[string][]streamType{ - "2.0.0": []streamType{streamTypeMsgApp}, - "2.1.0": []streamType{streamTypeMsgApp, streamTypeMsgAppV2, streamTypeMessage}, - "2.2.0": []streamType{streamTypeMsgApp, streamTypeMsgAppV2, streamTypeMessage}, + "2.0.0": {streamTypeMsgApp}, + "2.1.0": {streamTypeMsgApp, streamTypeMsgAppV2, streamTypeMessage}, + "2.2.0": {streamTypeMsgApp, streamTypeMsgAppV2, streamTypeMessage}, } ) diff --git a/rafthttp/transport.go b/rafthttp/transport.go index 31815a222..cafe7525e 100644 --- a/rafthttp/transport.go +++ b/rafthttp/transport.go @@ -214,7 +214,7 @@ func (t *transport) RemovePeer(id types.ID) { func (t *transport) RemoveAllPeers() { t.mu.Lock() defer t.mu.Unlock() - for id, _ := range t.peers { + for id := range t.peers { t.removePeer(id) } } diff --git a/storage/index_test.go b/storage/index_test.go index 2998d8ae3..88255b950 100644 --- a/storage/index_test.go +++ b/storage/index_test.go @@ -124,7 +124,7 @@ func TestContinuousCompact(t *testing.T) { {[]byte("foo2"), 6, nil, 4}, } wa := map[revision]struct{}{ - revision{main: 1}: struct{}{}, + revision{main: 1}: {}, } ga := index.Compact(1) if !reflect.DeepEqual(ga, wa) { @@ -133,8 +133,8 @@ func TestContinuousCompact(t *testing.T) { verify(t, index, tests) wa = map[revision]struct{}{ - revision{main: 1}: struct{}{}, - revision{main: 2}: struct{}{}, + revision{main: 1}: {}, + revision{main: 2}: {}, } ga = index.Compact(2) if !reflect.DeepEqual(ga, wa) { @@ -143,9 +143,9 @@ func TestContinuousCompact(t *testing.T) { verify(t, index, tests) wa = map[revision]struct{}{ - revision{main: 1}: struct{}{}, - revision{main: 2}: struct{}{}, - revision{main: 3}: struct{}{}, + revision{main: 1}: {}, + revision{main: 2}: {}, + revision{main: 3}: {}, } ga = index.Compact(3) if !reflect.DeepEqual(ga, wa) { @@ -154,9 +154,9 @@ func TestContinuousCompact(t *testing.T) { verify(t, index, tests) wa = map[revision]struct{}{ - revision{main: 1}: struct{}{}, - revision{main: 2}: struct{}{}, - revision{main: 4}: struct{}{}, + revision{main: 1}: {}, + revision{main: 2}: {}, + revision{main: 4}: {}, } ga = index.Compact(4) delete(wa, revision{main: 3}) @@ -167,9 +167,9 @@ func TestContinuousCompact(t *testing.T) { verify(t, index, tests) wa = map[revision]struct{}{ - revision{main: 2}: struct{}{}, - revision{main: 4}: struct{}{}, - revision{main: 5}: struct{}{}, + revision{main: 2}: {}, + revision{main: 4}: {}, + revision{main: 5}: {}, } ga = index.Compact(5) delete(wa, revision{main: 1}) @@ -181,9 +181,9 @@ func TestContinuousCompact(t *testing.T) { verify(t, index, tests) wa = map[revision]struct{}{ - revision{main: 4}: struct{}{}, - revision{main: 5}: struct{}{}, - revision{main: 6}: struct{}{}, + revision{main: 4}: {}, + revision{main: 5}: {}, + revision{main: 6}: {}, } ga = index.Compact(6) delete(wa, revision{main: 2}) diff --git a/storage/key_index_test.go b/storage/key_index_test.go index 1ea5f7f7a..568789ead 100644 --- a/storage/key_index_test.go +++ b/storage/key_index_test.go @@ -139,7 +139,7 @@ func TestKeyIndexCompact(t *testing.T) { }, }, map[revision]struct{}{ - revision{main: 2}: struct{}{}, + revision{main: 2}: {}, }, }, { @@ -154,7 +154,7 @@ func TestKeyIndexCompact(t *testing.T) { }, }, map[revision]struct{}{ - revision{main: 2}: struct{}{}, + revision{main: 2}: {}, }, }, { @@ -169,7 +169,7 @@ func TestKeyIndexCompact(t *testing.T) { }, }, map[revision]struct{}{ - revision{main: 4}: struct{}{}, + revision{main: 4}: {}, }, }, { @@ -184,7 +184,7 @@ func TestKeyIndexCompact(t *testing.T) { }, }, map[revision]struct{}{ - revision{main: 4}: struct{}{}, + revision{main: 4}: {}, }, }, { @@ -222,7 +222,7 @@ func TestKeyIndexCompact(t *testing.T) { }, }, map[revision]struct{}{ - revision{main: 8}: struct{}{}, + revision{main: 8}: {}, }, }, { @@ -236,7 +236,7 @@ func TestKeyIndexCompact(t *testing.T) { }, }, map[revision]struct{}{ - revision{main: 8}: struct{}{}, + revision{main: 8}: {}, }, }, { @@ -250,7 +250,7 @@ func TestKeyIndexCompact(t *testing.T) { }, }, map[revision]struct{}{ - revision{main: 10}: struct{}{}, + revision{main: 10}: {}, }, }, { @@ -264,7 +264,7 @@ func TestKeyIndexCompact(t *testing.T) { }, }, map[revision]struct{}{ - revision{main: 10}: struct{}{}, + revision{main: 10}: {}, }, }, { diff --git a/storage/revision_test.go b/storage/revision_test.go index d122ab07e..1f1b09181 100644 --- a/storage/revision_test.go +++ b/storage/revision_test.go @@ -13,11 +13,11 @@ import ( func TestRevision(t *testing.T) { tests := []revision{ // order in (main, sub) - revision{}, - revision{main: 1, sub: 0}, - revision{main: 1, sub: 1}, - revision{main: 2, sub: 0}, - revision{main: math.MaxInt64, sub: math.MaxInt64}, + {}, + {main: 1, sub: 0}, + {main: 1, sub: 1}, + {main: 2, sub: 0}, + {main: math.MaxInt64, sub: math.MaxInt64}, } bs := make([][]byte, len(tests)) diff --git a/test b/test index bb6a52e80..7876bf833 100755 --- a/test +++ b/test @@ -61,7 +61,7 @@ if [ -n "$INTEGRATION" ]; then fi echo "Checking gofmt..." -fmtRes=$(gofmt -l $FMT) +fmtRes=$(gofmt -l -s $FMT) if [ -n "${fmtRes}" ]; then echo -e "gofmt checking failed:\n${fmtRes}" exit 255