From 7de57ba4dea80b0fa02e517d673b0d727d2b5a3b Mon Sep 17 00:00:00 2001 From: Veselkov Konstantin Date: Sun, 28 Jan 2018 22:40:13 +0400 Subject: [PATCH 1/3] remove golint warnings --- agent/agent.go | 4 +- agent/consul/autopilot.go | 8 +-- agent/consul/util.go | 10 ++-- agent/dns.go | 14 +++--- agent/dns_test.go | 12 ++--- agent/metadata/server.go | 44 ++++++++-------- api/agent.go | 22 ++++---- api/api.go | 4 +- .../list/services/catalog_list_services.go | 2 +- command/rtt/rtt_test.go | 6 +-- lib/rtt.go | 4 +- lib/rtt_test.go | 50 +++++++++---------- 12 files changed, 90 insertions(+), 90 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index b078ee8836..c0a1c19126 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -609,9 +609,9 @@ func (a *Agent) reloadWatches(cfg *config.RuntimeConfig) error { for _, arg := range raw { if v, ok := arg.(string); !ok { return fmt.Errorf("Watch args must be a list of strings") - } else { - parsed = append(parsed, v) } + + parsed = append(parsed, v) } wp.Exempt["args"] = parsed } else if hasArgs && !ok { diff --git a/agent/consul/autopilot.go b/agent/consul/autopilot.go index 2c721d627d..5c5cf6ffed 100644 --- a/agent/consul/autopilot.go +++ b/agent/consul/autopilot.go @@ -31,13 +31,13 @@ func (d *AutopilotDelegate) IsServer(m serf.Member) (*autopilot.ServerInfo, erro return nil, nil } - port_str := m.Tags["port"] - port, err := strconv.Atoi(port_str) + portStr := m.Tags["port"] + port, err := strconv.Atoi(portStr) if err != nil { return nil, err } - build_version, err := metadata.Build(&m) + buildVersion, err := metadata.Build(&m) if err != nil { return nil, err } @@ -46,7 +46,7 @@ func (d *AutopilotDelegate) IsServer(m serf.Member) (*autopilot.ServerInfo, erro Name: m.Name, ID: m.Tags["id"], Addr: &net.TCPAddr{IP: m.Addr, Port: port}, - Build: *build_version, + Build: *buildVersion, Status: m.Status, } return server, nil diff --git a/agent/consul/util.go b/agent/consul/util.go index 14a2ab0154..9634aa089b 100644 --- a/agent/consul/util.go +++ b/agent/consul/util.go @@ -75,18 +75,18 @@ func CanServersUnderstandProtocol(members []serf.Member, version uint8) (bool, e } numServers++ - vsn_min, err := strconv.Atoi(m.Tags["vsn_min"]) + vsnMin, err := strconv.Atoi(m.Tags["vsn_min"]) if err != nil { return false, err } - vsn_max, err := strconv.Atoi(m.Tags["vsn_max"]) + vsnMax, err := strconv.Atoi(m.Tags["vsn_max"]) if err != nil { return false, err } v := int(version) - if (v >= vsn_min) && (v <= vsn_max) { + if (v >= vsnMin) && (v <= vsnMax) { numWhoGrok++ } } @@ -103,8 +103,8 @@ func isConsulNode(m serf.Member) (bool, string) { } // Returns if the given IP is in a private block -func isPrivateIP(ip_str string) bool { - ip := net.ParseIP(ip_str) +func isPrivateIP(ipStr string) bool { + ip := net.ParseIP(ipStr) for _, priv := range privateBlocks { if priv.Contains(ip) { return true diff --git a/agent/dns.go b/agent/dns.go index d77a51735e..af5e53f73c 100644 --- a/agent/dns.go +++ b/agent/dns.go @@ -107,12 +107,12 @@ func GetDNSConfig(conf *config.RuntimeConfig) *dnsConfig { } } -func (s *DNSServer) ListenAndServe(network, addr string, notif func()) error { +func (d *DNSServer) ListenAndServe(network, addr string, notif func()) error { mux := dns.NewServeMux() - mux.HandleFunc("arpa.", s.handlePtr) - mux.HandleFunc(s.domain, s.handleQuery) - if len(s.recursors) > 0 { - mux.HandleFunc(".", s.handleRecurse) + mux.HandleFunc("arpa.", d.handlePtr) + mux.HandleFunc(s.domain, dhandleQuery) + if len(d.recursors) > 0 { + mux.HandleFunc(".", d.handleRecurse) } s.Server = &dns.Server{ @@ -122,9 +122,9 @@ func (s *DNSServer) ListenAndServe(network, addr string, notif func()) error { NotifyStartedFunc: notif, } if network == "udp" { - s.UDPSize = 65535 + d.UDPSize = 65535 } - return s.Server.ListenAndServe() + return d.Server.ListenAndServe() } // recursorAddr is used to add a port to the recursor if omitted. diff --git a/agent/dns_test.go b/agent/dns_test.go index ba9006b2ff..00ba064569 100644 --- a/agent/dns_test.go +++ b/agent/dns_test.go @@ -2877,7 +2877,7 @@ func TestDNS_ServiceLookup_LargeResponses(t *testing.T) { } } -func testDNS_ServiceLookup_responseLimits(t *testing.T, answerLimit int, qType uint16, +func testDNSServiceLookupResponseLimits(t *testing.T, answerLimit int, qType uint16, expectedService, expectedQuery, expectedQueryID int) (bool, error) { a := NewTestAgent(t.Name(), ` node_name = "test-node" @@ -3007,7 +3007,7 @@ func TestDNS_ServiceLookup_AnswerLimits(t *testing.T) { test := test // capture loop var t.Run("A lookup", func(t *testing.T) { t.Parallel() - ok, err := testDNS_ServiceLookup_responseLimits(t, test.udpAnswerLimit, dns.TypeA, test.expectedAService, test.expectedAQuery, test.expectedAQueryID) + ok, err := testDNSServiceLookupResponseLimits(t, test.udpAnswerLimit, dns.TypeA, test.expectedAService, test.expectedAQuery, test.expectedAQueryID) if !ok { t.Errorf("Expected service A lookup %s to pass: %v", test.name, err) } @@ -3015,7 +3015,7 @@ func TestDNS_ServiceLookup_AnswerLimits(t *testing.T) { t.Run("AAAA lookup", func(t *testing.T) { t.Parallel() - ok, err := testDNS_ServiceLookup_responseLimits(t, test.udpAnswerLimit, dns.TypeAAAA, test.expectedAAAAService, test.expectedAAAAQuery, test.expectedAAAAQueryID) + ok, err := testDNSServiceLookupResponseLimits(t, test.udpAnswerLimit, dns.TypeAAAA, test.expectedAAAAService, test.expectedAAAAQuery, test.expectedAAAAQueryID) if !ok { t.Errorf("Expected service AAAA lookup %s to pass: %v", test.name, err) } @@ -3023,7 +3023,7 @@ func TestDNS_ServiceLookup_AnswerLimits(t *testing.T) { t.Run("ANY lookup", func(t *testing.T) { t.Parallel() - ok, err := testDNS_ServiceLookup_responseLimits(t, test.udpAnswerLimit, dns.TypeANY, test.expectedANYService, test.expectedANYQuery, test.expectedANYQueryID) + ok, err := testDNSServiceLookupResponseLimits(t, test.udpAnswerLimit, dns.TypeANY, test.expectedANYService, test.expectedANYQuery, test.expectedANYQueryID) if !ok { t.Errorf("Expected service ANY lookup %s to pass: %v", test.name, err) } @@ -3620,8 +3620,8 @@ func TestDNS_PreparedQuery_Failover(t *testing.T) { m.SetQuestion("my-query.query.consul.", dns.TypeSRV) c := new(dns.Client) - cl_addr := a1.config.DNSAddrs[0] - in, _, err := c.Exchange(m, cl_addr.String()) + clAddr := a1.config.DNSAddrs[0] + in, _, err := c.Exchange(m, clAddr.String()) if err != nil { t.Fatalf("err: %v", err) } diff --git a/agent/metadata/server.go b/agent/metadata/server.go index b2873ed221..51775fb980 100644 --- a/agent/metadata/server.go +++ b/agent/metadata/server.go @@ -76,64 +76,64 @@ func IsConsulServer(m serf.Member) (bool, *Server) { _, useTLS := m.Tags["use_tls"] expect := 0 - expect_str, ok := m.Tags["expect"] + expectStr, ok := m.Tags["expect"] var err error if ok { - expect, err = strconv.Atoi(expect_str) + expect, err = strconv.Atoi(expectStr) if err != nil { return false, nil } } - port_str := m.Tags["port"] - port, err := strconv.Atoi(port_str) + portStr := m.Tags["port"] + port, err := strconv.Atoi(portStr) if err != nil { return false, nil } - segment_addrs := make(map[string]string) - segment_ports := make(map[string]int) + segmentAddrs := make(map[string]string) + segmentPorts := make(map[string]int) for name, value := range m.Tags { if strings.HasPrefix(name, "sl_") { addr, port, err := net.SplitHostPort(value) if err != nil { return false, nil } - segment_port, err := strconv.Atoi(port) + segmentPort, err := strconv.Atoi(port) if err != nil { return false, nil } - segment_name := strings.TrimPrefix(name, "sl_") - segment_addrs[segment_name] = addr - segment_ports[segment_name] = segment_port + segmentName := strings.TrimPrefix(name, "sl_") + segmentAddrs[segmentName] = addr + segmentPorts[segmentName] = segmentPort } } - build_version, err := Build(&m) + buildVersion, err := Build(&m) if err != nil { return false, nil } - wan_join_port := 0 - wan_join_port_str, ok := m.Tags["wan_join_port"] + wanJoinPort := 0 + wanJoinPortStr, ok := m.Tags["wan_join_port"] if ok { - wan_join_port, err = strconv.Atoi(wan_join_port_str) + wanJoinPort, err = strconv.Atoi(wanJoinPortStr) if err != nil { return false, nil } } - vsn_str := m.Tags["vsn"] - vsn, err := strconv.Atoi(vsn_str) + vsnStr := m.Tags["vsn"] + vsn, err := strconv.Atoi(vsnStr) if err != nil { return false, nil } - raft_vsn := 0 + raftVsn := 0 raft_vsn_str, ok := m.Tags["raft_vsn"] if ok { - raft_vsn, err = strconv.Atoi(raft_vsn_str) + raftVsn, err = strconv.Atoi(raft_vsn_str) if err != nil { return false, nil } @@ -147,15 +147,15 @@ func IsConsulServer(m serf.Member) (bool, *Server) { Datacenter: datacenter, Segment: segment, Port: port, - SegmentAddrs: segment_addrs, - SegmentPorts: segment_ports, + SegmentAddrs: segmentAddrs, + SegmentPorts: segmentPorts, WanJoinPort: wan_join_port, Bootstrap: bootstrap, Expect: expect, Addr: addr, - Build: *build_version, + Build: *buildVersion, Version: vsn, - RaftVersion: raft_vsn, + RaftVersion: raftVsn, Status: m.Status, UseTLS: useTLS, } diff --git a/api/agent.go b/api/agent.go index 8509276ace..2c826660cd 100644 --- a/api/agent.go +++ b/api/agent.go @@ -584,36 +584,36 @@ func (a *Agent) Monitor(loglevel string, stopCh <-chan struct{}, q *QueryOptions // UpdateACLToken updates the agent's "acl_token". See updateToken for more // details. -func (c *Agent) UpdateACLToken(token string, q *WriteOptions) (*WriteMeta, error) { - return c.updateToken("acl_token", token, q) +func (a *Agent) UpdateACLToken(token string, q *WriteOptions) (*WriteMeta, error) { + return a.updateToken("acl_token", token, q) } // UpdateACLAgentToken updates the agent's "acl_agent_token". See updateToken // for more details. -func (c *Agent) UpdateACLAgentToken(token string, q *WriteOptions) (*WriteMeta, error) { - return c.updateToken("acl_agent_token", token, q) +func (a *Agent) UpdateACLAgentToken(token string, q *WriteOptions) (*WriteMeta, error) { + return a.updateToken("acl_agent_token", token, q) } // UpdateACLAgentMasterToken updates the agent's "acl_agent_master_token". See // updateToken for more details. -func (c *Agent) UpdateACLAgentMasterToken(token string, q *WriteOptions) (*WriteMeta, error) { - return c.updateToken("acl_agent_master_token", token, q) +func (a *Agent) UpdateACLAgentMasterToken(token string, q *WriteOptions) (*WriteMeta, error) { + return a.updateToken("acl_agent_master_token", token, q) } // UpdateACLReplicationToken updates the agent's "acl_replication_token". See // updateToken for more details. -func (c *Agent) UpdateACLReplicationToken(token string, q *WriteOptions) (*WriteMeta, error) { - return c.updateToken("acl_replication_token", token, q) +func (a *Agent) UpdateACLReplicationToken(token string, q *WriteOptions) (*WriteMeta, error) { + return a.updateToken("acl_replication_token", token, q) } // updateToken can be used to update an agent's ACL token after the agent has // started. The tokens are not persisted, so will need to be updated again if // the agent is restarted. -func (c *Agent) updateToken(target, token string, q *WriteOptions) (*WriteMeta, error) { - r := c.c.newRequest("PUT", fmt.Sprintf("/v1/agent/token/%s", target)) +func (a *Agent) updateToken(target, token string, q *WriteOptions) (*WriteMeta, error) { + r := a.c.newRequest("PUT", fmt.Sprintf("/v1/agent/token/%s", target)) r.setWriteOptions(q) r.obj = &AgentToken{Token: token} - rtt, resp, err := requireOK(c.c.doRequest(r)) + rtt, resp, err := requireOK(a.c.doRequest(r)) if err != nil { return nil, err } diff --git a/api/api.go b/api/api.go index 7db12b49d7..b756ceb063 100644 --- a/api/api.go +++ b/api/api.go @@ -633,9 +633,9 @@ func (r *request) toHTTP() (*http.Request, error) { } if r.ctx != nil { return req.WithContext(r.ctx), nil - } else { - return req, nil } + + return req, nil } // newRequest is used to create a new request diff --git a/command/catalog/list/services/catalog_list_services.go b/command/catalog/list/services/catalog_list_services.go index fb769e804d..bc9ce3b251 100644 --- a/command/catalog/list/services/catalog_list_services.go +++ b/command/catalog/list/services/catalog_list_services.go @@ -99,7 +99,7 @@ func (c *cmd) Run(args []string) int { // Order the map for consistent output order := make([]string, 0, len(services)) - for k, _ := range services { + for k := range services { order = append(order, k) } sort.Strings(order) diff --git a/command/rtt/rtt_test.go b/command/rtt/rtt_test.go index 120ce0378c..b866453a24 100644 --- a/command/rtt/rtt_test.go +++ b/command/rtt/rtt_test.go @@ -57,7 +57,7 @@ func TestRTTCommand_LAN(t *testing.T) { c1 := coordinate.NewCoordinate(coordinate.DefaultConfig()) c2 := c1.Clone() c2.Vec[0] = 0.123 - dist_str := fmt.Sprintf("%.3f ms", c1.DistanceTo(c2).Seconds()*1000.0) + distStr := fmt.Sprintf("%.3f ms", c1.DistanceTo(c2).Seconds()*1000.0) { req := structs.CoordinateUpdateRequest{ Datacenter: a.Config.Datacenter, @@ -108,7 +108,7 @@ func TestRTTCommand_LAN(t *testing.T) { } // Make sure the proper RTT was reported in the output. - expected := fmt.Sprintf("rtt: %s", dist_str) + expected := fmt.Sprintf("rtt: %s", distStr) if !strings.Contains(ui.OutputWriter.String(), expected) { r.Fatalf("bad: %#v", ui.OutputWriter.String()) } @@ -128,7 +128,7 @@ func TestRTTCommand_LAN(t *testing.T) { } // Make sure the proper RTT was reported in the output. - expected := fmt.Sprintf("rtt: %s", dist_str) + expected := fmt.Sprintf("rtt: %s", distStr) if !strings.Contains(ui.OutputWriter.String(), expected) { t.Fatalf("bad: %#v", ui.OutputWriter.String()) } diff --git a/lib/rtt.go b/lib/rtt.go index a417f533c9..fb9090ab1d 100644 --- a/lib/rtt.go +++ b/lib/rtt.go @@ -36,14 +36,14 @@ func (cs CoordinateSet) Intersect(other CoordinateSet) (*coordinate.Coordinate, // we are possibly a client. Any node with more than one segment can only // be a server, which means it should be in all segments. if len(cs) == 1 { - for s, _ := range cs { + for s := range cs { segment = s } } // Likewise for the other set. if len(other) == 1 { - for s, _ := range other { + for s := range other { segment = s } } diff --git a/lib/rtt_test.go b/lib/rtt_test.go index 22004494dd..403b49db1a 100644 --- a/lib/rtt_test.go +++ b/lib/rtt_test.go @@ -70,23 +70,23 @@ func TestRTT_ComputeDistance(t *testing.T) { func TestRTT_Intersect(t *testing.T) { // The numbers here don't matter, we just want a unique coordinate for // each one. - server_1 := CoordinateSet{ + server1 := CoordinateSet{ "": GenerateCoordinate(1 * time.Millisecond), "alpha": GenerateCoordinate(2 * time.Millisecond), "beta": GenerateCoordinate(3 * time.Millisecond), } - server_2 := CoordinateSet{ + server2 := CoordinateSet{ "": GenerateCoordinate(4 * time.Millisecond), "alpha": GenerateCoordinate(5 * time.Millisecond), "beta": GenerateCoordinate(6 * time.Millisecond), } - client_alpha := CoordinateSet{ + clientAlpha := CoordinateSet{ "alpha": GenerateCoordinate(7 * time.Millisecond), } - client_beta_1 := CoordinateSet{ + clientBeta1 := CoordinateSet{ "beta": GenerateCoordinate(8 * time.Millisecond), } - client_beta_2 := CoordinateSet{ + clientBeta2 := CoordinateSet{ "beta": GenerateCoordinate(9 * time.Millisecond), } @@ -104,43 +104,43 @@ func TestRTT_Intersect(t *testing.T) { }, { "two servers", - server_1, server_2, - server_1[""], server_2[""], + server1, server2, + server1[""], server2[""], }, { "two clients", - client_beta_1, client_beta_2, - client_beta_1["beta"], client_beta_2["beta"], + clientBeta1, clientBeta2, + clientBeta1["beta"], clientBeta2["beta"], }, { - "server_1 and client alpha", - server_1, client_alpha, - server_1["alpha"], client_alpha["alpha"], + "server1 and client alpha", + server1, clientAlpha, + server1["alpha"], clientAlpha["alpha"], }, { - "server_1 and client beta 1", - server_1, client_beta_1, - server_1["beta"], client_beta_1["beta"], + "server1 and client beta 1", + server1, clientBeta1, + server1["beta"], clientBeta1["beta"], }, { - "server_1 and client alpha reversed", - client_alpha, server_1, - client_alpha["alpha"], server_1["alpha"], + "server1 and client alpha reversed", + clientAlpha, server1, + clientAlpha["alpha"], server1["alpha"], }, { - "server_1 and client beta 1 reversed", - client_beta_1, server_1, - client_beta_1["beta"], server_1["beta"], + "server1 and client beta 1 reversed", + clientBeta1, server1, + clientBeta1["beta"], server1["beta"], }, { "nothing in common", - client_alpha, client_beta_1, - nil, client_beta_1["beta"], + clientAlpha, clientBeta1, + nil, clientBeta1["beta"], }, { "nothing in common reversed", - client_beta_1, client_alpha, - nil, client_alpha["alpha"], + clientBeta1, clientAlpha, + nil, clientAlpha["alpha"], }, } for _, tt := range tests { From 8e16bd7d7707cf8faedcc834050ae7170cee6f4f Mon Sep 17 00:00:00 2001 From: Veselkov Konstantin Date: Sun, 28 Jan 2018 22:48:21 +0400 Subject: [PATCH 2/3] fix refactoring --- agent/metadata/server.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/agent/metadata/server.go b/agent/metadata/server.go index 51775fb980..957de88f05 100644 --- a/agent/metadata/server.go +++ b/agent/metadata/server.go @@ -131,9 +131,9 @@ func IsConsulServer(m serf.Member) (bool, *Server) { } raftVsn := 0 - raft_vsn_str, ok := m.Tags["raft_vsn"] + raftVsnStr, ok := m.Tags["raft_vsn"] if ok { - raftVsn, err = strconv.Atoi(raft_vsn_str) + raftVsn, err = strconv.Atoi(raftVsnStr) if err != nil { return false, nil } @@ -149,7 +149,7 @@ func IsConsulServer(m serf.Member) (bool, *Server) { Port: port, SegmentAddrs: segmentAddrs, SegmentPorts: segmentPorts, - WanJoinPort: wan_join_port, + WanJoinPort: wanJoinPort, Bootstrap: bootstrap, Expect: expect, Addr: addr, From 5f38e1148a308615bdcb9945ba6c438574625a3f Mon Sep 17 00:00:00 2001 From: Veselkov Konstantin Date: Sun, 28 Jan 2018 22:53:30 +0400 Subject: [PATCH 3/3] fix refactoring --- agent/agent.go | 3 ++- agent/dns.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index c0a1c19126..2069265082 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -607,7 +607,8 @@ func (a *Agent) reloadWatches(cfg *config.RuntimeConfig) error { if raw, ok := args.([]interface{}); hasArgs && ok { var parsed []string for _, arg := range raw { - if v, ok := arg.(string); !ok { + v, ok := arg.(string) + if !ok { return fmt.Errorf("Watch args must be a list of strings") } diff --git a/agent/dns.go b/agent/dns.go index af5e53f73c..c842f07136 100644 --- a/agent/dns.go +++ b/agent/dns.go @@ -110,12 +110,12 @@ func GetDNSConfig(conf *config.RuntimeConfig) *dnsConfig { func (d *DNSServer) ListenAndServe(network, addr string, notif func()) error { mux := dns.NewServeMux() mux.HandleFunc("arpa.", d.handlePtr) - mux.HandleFunc(s.domain, dhandleQuery) + mux.HandleFunc(d.domain, d.handleQuery) if len(d.recursors) > 0 { mux.HandleFunc(".", d.handleRecurse) } - s.Server = &dns.Server{ + d.Server = &dns.Server{ Addr: addr, Net: network, Handler: mux,