From b6053d6a86bab62ad745fe139bb729a4cfec5a3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Senart?= Date: Thu, 27 Mar 2014 14:19:08 +0100 Subject: [PATCH] Making code formatting consistent. $ gofmt -s -w && goimports -w --- log/log.go | 3 +- metrics/standard.go | 20 +++++------ mod/dashboard/resources/resources.go | 34 +++++++++---------- mod/leader/v2/handler.go | 14 ++++---- mod/lock/v2/handler.go | 6 ++-- server/registry.go | 4 +-- server/v1/delete_key_handler.go | 3 +- server/v1/v1.go | 3 +- server/v2/v2.go | 3 +- store/v2/update_command.go | 3 +- tests/functional/discovery_test.go | 4 +-- tests/functional/etcd_tls_test.go | 9 +++-- .../multi_node_kill_all_and_recovery_test.go | 4 +-- tests/functional/proxy_test.go | 2 +- tests/functional/util.go | 5 +-- tests/mock/mock_store.go | 3 +- 16 files changed, 62 insertions(+), 58 deletions(-) diff --git a/log/log.go b/log/log.go index bdedc56b1..82a2dec99 100644 --- a/log/log.go +++ b/log/log.go @@ -1,8 +1,9 @@ package log import ( - golog "github.com/coreos/etcd/third_party/github.com/coreos/go-log/log" "os" + + golog "github.com/coreos/etcd/third_party/github.com/coreos/go-log/log" ) // The Verbose flag turns on verbose logging. diff --git a/metrics/standard.go b/metrics/standard.go index fc6a01f00..4d2f6e576 100644 --- a/metrics/standard.go +++ b/metrics/standard.go @@ -12,19 +12,19 @@ import ( const ( // RuntimeMemStatsSampleInterval is the interval in seconds at which the // Go runtime's memory statistics will be gathered. - RuntimeMemStatsSampleInterval = time.Duration(2) * time.Second + RuntimeMemStatsSampleInterval = time.Duration(2) * time.Second // GraphitePublishInterval is the interval in seconds at which all // gathered statistics will be published to a Graphite endpoint. - GraphitePublishInterval = time.Duration(2) * time.Second + GraphitePublishInterval = time.Duration(2) * time.Second ) type standardBucket struct { sync.Mutex - name string - registry gometrics.Registry - timers map[string]Timer - gauges map[string]Gauge + name string + registry gometrics.Registry + timers map[string]Timer + gauges map[string]Gauge } func newStandardBucket(name string) standardBucket { @@ -34,10 +34,10 @@ func newStandardBucket(name string) standardBucket { go gometrics.CaptureRuntimeMemStats(registry, RuntimeMemStatsSampleInterval) return standardBucket{ - name: name, - registry: registry, - timers: make(map[string]Timer), - gauges: make(map[string]Gauge), + name: name, + registry: registry, + timers: make(map[string]Timer), + gauges: make(map[string]Gauge), } } diff --git a/mod/dashboard/resources/resources.go b/mod/dashboard/resources/resources.go index a1534c227..ba6f0b314 100644 --- a/mod/dashboard/resources/resources.go +++ b/mod/dashboard/resources/resources.go @@ -1,12 +1,12 @@ package resources import ( - "bytes" - "compress/gzip" - "fmt" - "io" - "reflect" - "unsafe" + "bytes" + "compress/gzip" + "fmt" + "io" + "reflect" + "unsafe" ) func bindata_read(data, name string) ([]byte, error) { @@ -133,7 +133,6 @@ func views_stats_html() ([]byte, error) { ) } - // Asset loads and returns the asset for the given name. // It returns an error if the asset could not be found or // could not be loaded. @@ -145,17 +144,16 @@ func Asset(name string) ([]byte, error) { } // _bindata is a table, holding each asset generator, mapped to its name. -var _bindata = map[string] func() ([]byte, error) { - "index.html": index_html, - "images/add.svg": images_add_svg, - "images/back.svg": images_back_svg, - "images/delete.svg": images_delete_svg, - "images/logo.svg": images_logo_svg, - "scripts/app.js": scripts_app_js, +var _bindata = map[string]func() ([]byte, error){ + "index.html": index_html, + "images/add.svg": images_add_svg, + "images/back.svg": images_back_svg, + "images/delete.svg": images_delete_svg, + "images/logo.svg": images_logo_svg, + "scripts/app.js": scripts_app_js, "scripts/modules.js": scripts_modules_js, - "styles/styles.css": styles_styles_css, + "styles/styles.css": styles_styles_css, "views/browser.html": views_browser_html, - "views/home.html": views_home_html, - "views/stats.html": views_stats_html, - + "views/home.html": views_home_html, + "views/stats.html": views_stats_html, } diff --git a/mod/leader/v2/handler.go b/mod/leader/v2/handler.go index fac8e3b4d..7e9108b19 100644 --- a/mod/leader/v2/handler.go +++ b/mod/leader/v2/handler.go @@ -13,19 +13,19 @@ const prefix = "/_mod/leader" // handler manages the leader HTTP request. type handler struct { *mux.Router - client *http.Client - transport *http.Transport - addr string + client *http.Client + transport *http.Transport + addr string } // NewHandler creates an HTTP handler that can be registered on a router. func NewHandler(addr string) http.Handler { transport := &http.Transport{DisableKeepAlives: false} h := &handler{ - Router: mux.NewRouter(), - client: &http.Client{Transport: transport}, - transport: transport, - addr: addr, + Router: mux.NewRouter(), + client: &http.Client{Transport: transport}, + transport: transport, + addr: addr, } h.StrictSlash(false) h.handleFunc("/{key:.*}", h.getHandler).Methods("GET") diff --git a/mod/lock/v2/handler.go b/mod/lock/v2/handler.go index fa4797de2..313e6eab0 100644 --- a/mod/lock/v2/handler.go +++ b/mod/lock/v2/handler.go @@ -13,14 +13,14 @@ const prefix = "/_etcd/mod/lock" // handler manages the lock HTTP request. type handler struct { *mux.Router - client *etcd.Client + client *etcd.Client } // NewHandler creates an HTTP handler that can be registered on a router. func NewHandler(addr string) http.Handler { h := &handler{ - Router: mux.NewRouter(), - client: etcd.NewClient([]string{addr}), + Router: mux.NewRouter(), + client: etcd.NewClient([]string{addr}), } h.StrictSlash(false) h.handleFunc("/{key:.*}", h.getIndexHandler).Methods("GET") diff --git a/server/registry.go b/server/registry.go index 54fd884f7..f6de5d674 100644 --- a/server/registry.go +++ b/server/registry.go @@ -46,7 +46,7 @@ func NewRegistry(s store.Store) *Registry { // Peers returns a list of cached peer names. func (r *Registry) Peers() []string { names := make([]string, 0, len(r.peers)) - for name, _ := range r.peers { + for name := range r.peers { names = append(names, name) } sort.Sort(sort.StringSlice(names)) @@ -56,7 +56,7 @@ func (r *Registry) Peers() []string { // Proxies returns a list of cached proxy names. func (r *Registry) Proxies() []string { names := make([]string, 0, len(r.proxies)) - for name, _ := range r.proxies { + for name := range r.proxies { names = append(names, name) } sort.Sort(sort.StringSlice(names)) diff --git a/server/v1/delete_key_handler.go b/server/v1/delete_key_handler.go index 75fab02a1..fd147601d 100644 --- a/server/v1/delete_key_handler.go +++ b/server/v1/delete_key_handler.go @@ -1,8 +1,9 @@ package v1 import ( - "github.com/coreos/etcd/third_party/github.com/gorilla/mux" "net/http" + + "github.com/coreos/etcd/third_party/github.com/gorilla/mux" ) // Removes a key from the store. diff --git a/server/v1/v1.go b/server/v1/v1.go index 6fed2c6e6..e0c7dc5ff 100644 --- a/server/v1/v1.go +++ b/server/v1/v1.go @@ -1,9 +1,10 @@ package v1 import ( + "net/http" + "github.com/coreos/etcd/store" "github.com/coreos/etcd/third_party/github.com/goraft/raft" - "net/http" ) // The Server interface provides all the methods required for the v1 API. diff --git a/server/v2/v2.go b/server/v2/v2.go index 0a441741e..72a59d9d7 100644 --- a/server/v2/v2.go +++ b/server/v2/v2.go @@ -1,9 +1,10 @@ package v2 import ( + "net/http" + "github.com/coreos/etcd/store" "github.com/coreos/etcd/third_party/github.com/goraft/raft" - "net/http" ) // The Server interface provides all the methods required for the v2 API. diff --git a/store/v2/update_command.go b/store/v2/update_command.go index 13efc1281..8678c1dad 100644 --- a/store/v2/update_command.go +++ b/store/v2/update_command.go @@ -1,10 +1,11 @@ package v2 import ( + "time" + "github.com/coreos/etcd/log" "github.com/coreos/etcd/store" "github.com/coreos/etcd/third_party/github.com/goraft/raft" - "time" ) func init() { diff --git a/tests/functional/discovery_test.go b/tests/functional/discovery_test.go index 16f3d2331..9a8c2ea3a 100644 --- a/tests/functional/discovery_test.go +++ b/tests/functional/discovery_test.go @@ -12,8 +12,8 @@ import ( "github.com/coreos/etcd/third_party/github.com/stretchr/testify/assert" - etcdtest "github.com/coreos/etcd/tests" "github.com/coreos/etcd/server" + etcdtest "github.com/coreos/etcd/tests" goetcd "github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd" ) @@ -294,7 +294,7 @@ func TestDiscoverySecondPeerUp(t *testing.T) { func assertServerNotUp(client http.Client, scheme string) error { path := fmt.Sprintf("%s://127.0.0.1:4001/v2/keys/foo", scheme) - fields := url.Values(map[string][]string{"value": []string{"bar"}}) + fields := url.Values(map[string][]string{"value": {"bar"}}) for i := 0; i < 10; i++ { time.Sleep(1 * time.Second) diff --git a/tests/functional/etcd_tls_test.go b/tests/functional/etcd_tls_test.go index 0f727070f..1089dcd04 100644 --- a/tests/functional/etcd_tls_test.go +++ b/tests/functional/etcd_tls_test.go @@ -145,7 +145,6 @@ func TestTLSUnauthenticatedClient(t *testing.T) { } } - func buildClient() http.Client { return http.Client{} } @@ -159,7 +158,7 @@ func startServer(extra []string) (*os.Process, error) { procAttr := new(os.ProcAttr) procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr} - cmd := []string{"etcd", "-f", "-data-dir=/tmp/node1", "-name=node1"} + cmd := []string{"etcd", "-f", "-data-dir=/tmp/node1", "-name=node1"} cmd = append(cmd, extra...) println(strings.Join(cmd, " ")) @@ -171,7 +170,7 @@ func startServerWithDataDir(extra []string) (*os.Process, error) { procAttr := new(os.ProcAttr) procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr} - cmd := []string{"etcd", "-data-dir=/tmp/node1", "-name=node1"} + cmd := []string{"etcd", "-data-dir=/tmp/node1", "-name=node1"} cmd = append(cmd, extra...) println(strings.Join(cmd, " ")) @@ -189,7 +188,7 @@ func stopServer(proc *os.Process) { func assertServerFunctional(client http.Client, scheme string) error { path := fmt.Sprintf("%s://127.0.0.1:4001/v2/keys/foo", scheme) - fields := url.Values(map[string][]string{"value": []string{"bar"}}) + fields := url.Values(map[string][]string{"value": {"bar"}}) for i := 0; i < 10; i++ { time.Sleep(1 * time.Second) @@ -220,7 +219,7 @@ func assertServerFunctional(client http.Client, scheme string) error { func assertServerNotFunctional(client http.Client, scheme string) error { path := fmt.Sprintf("%s://127.0.0.1:4001/v2/keys/foo", scheme) - fields := url.Values(map[string][]string{"value": []string{"bar"}}) + fields := url.Values(map[string][]string{"value": {"bar"}}) for i := 0; i < 10; i++ { time.Sleep(1 * time.Second) diff --git a/tests/functional/multi_node_kill_all_and_recovery_test.go b/tests/functional/multi_node_kill_all_and_recovery_test.go index 2f1511f98..aaa2fc01c 100644 --- a/tests/functional/multi_node_kill_all_and_recovery_test.go +++ b/tests/functional/multi_node_kill_all_and_recovery_test.go @@ -31,7 +31,7 @@ func TestMultiNodeKillAllAndRecovery(t *testing.T) { go Monitor(clusterSize, clusterSize, leaderChan, all, stop) <-all <-leaderChan - stop <-true + stop <- true c.SyncCluster() @@ -102,7 +102,7 @@ func TestTLSMultiNodeKillAllAndRecovery(t *testing.T) { go Monitor(clusterSize, clusterSize, leaderChan, all, stop) <-all <-leaderChan - stop <-true + stop <- true c.SyncCluster() diff --git a/tests/functional/proxy_test.go b/tests/functional/proxy_test.go index 665862aad..29ef23e07 100644 --- a/tests/functional/proxy_test.go +++ b/tests/functional/proxy_test.go @@ -35,7 +35,7 @@ func TestProxy(t *testing.T) { time.Sleep(time.Second) // Check that all peers and proxies have the value. - for i, _ := range etcds { + for i := range etcds { resp, err := tests.Get(fmt.Sprintf("http://localhost:%d/v2/keys/foo", 4000+(i+1))) if assert.NoError(t, err) { body := tests.ReadBodyJSON(resp) diff --git a/tests/functional/util.go b/tests/functional/util.go index 9e5284cc2..646dc9307 100644 --- a/tests/functional/util.go +++ b/tests/functional/util.go @@ -19,13 +19,14 @@ package test import ( "errors" "fmt" - "github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd" "io/ioutil" "net" "net/http" "os" "strconv" "time" + + "github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd" ) var client = http.Client{ @@ -109,7 +110,7 @@ func CreateCluster(size int, procAttr *os.ProcAttr, ssl bool) ([][]string, []*os } } else { strI := strconv.Itoa(i + 1) - argGroup[i] = []string{"etcd", "-name=node" + strI, fmt.Sprintf("-addr=127.0.0.1:%d", 4001 + i), fmt.Sprintf("-peer-addr=127.0.0.1:%d", 7001 + i), "-data-dir=/tmp/node" + strI, "-peers=127.0.0.1:7001"} + argGroup[i] = []string{"etcd", "-name=node" + strI, fmt.Sprintf("-addr=127.0.0.1:%d", 4001+i), fmt.Sprintf("-peer-addr=127.0.0.1:%d", 7001+i), "-data-dir=/tmp/node" + strI, "-peers=127.0.0.1:7001"} if ssl { argGroup[i] = append(argGroup[i], sslServer2...) } diff --git a/tests/mock/mock_store.go b/tests/mock/mock_store.go index a4b662368..cb2a5cfdc 100644 --- a/tests/mock/mock_store.go +++ b/tests/mock/mock_store.go @@ -1,9 +1,10 @@ package mock import ( + "time" + "github.com/coreos/etcd/store" "github.com/stretchr/testify/mock" - "time" ) // A mock Store object used for testing.