remove golint warnings

This commit is contained in:
Veselkov Konstantin 2018-01-28 22:40:13 +04:00
parent 842ae5a248
commit 7de57ba4de
12 changed files with 90 additions and 90 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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)
}

View File

@ -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,
}

View File

@ -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
}

View File

@ -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

View File

@ -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)

View File

@ -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())
}

View File

@ -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
}
}

View File

@ -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 {