Add gosimple linter (#9590)

This commit is contained in:
Kris Hicks
2020-12-09 11:05:18 -08:00
committed by GitHub
parent 8333ab9f80
commit 85ed8ddd4f
77 changed files with 111 additions and 186 deletions

View File

@@ -111,7 +111,7 @@ func formatPolicies(policies []*api.ACLPolicyListStub) string {
}
output := make([]string, 0, len(policies)+1)
output = append(output, fmt.Sprintf("Name|Description"))
output = append(output, "Name|Description")
for _, p := range policies {
output = append(output, fmt.Sprintf("%s|%s", p.Name, p.Description))
}

View File

@@ -108,7 +108,7 @@ func formatTokens(tokens []*api.ACLTokenListStub) string {
}
output := make([]string, 0, len(tokens)+1)
output = append(output, fmt.Sprintf("Name|Type|Global|Accessor ID"))
output = append(output, "Name|Type|Global|Accessor ID")
for _, p := range tokens {
output = append(output, fmt.Sprintf("%s|%s|%t|%s", p.Name, p.Type, p.Global, p.AccessorID))
}

View File

@@ -882,7 +882,7 @@ func (c *Command) handleReload() {
c.Ui.Output("Reloading configuration...")
newConf := c.readConfig()
if newConf == nil {
c.Ui.Error(fmt.Sprintf("Failed to reload configs"))
c.Ui.Error("Failed to reload configs")
return
}

View File

@@ -400,7 +400,6 @@ func (s *HTTPServer) handleUI(h http.Handler) http.Handler {
header := w.Header()
header.Add("Content-Security-Policy", "default-src 'none'; connect-src *; img-src 'self' data:; script-src 'self'; style-src 'self' 'unsafe-inline'; form-action 'none'; frame-ancestors 'none'")
h.ServeHTTP(w, req)
return
})
}
@@ -448,7 +447,7 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque
reqURL := req.URL.String()
start := time.Now()
defer func() {
s.logger.Debug("request complete", "method", req.Method, "path", reqURL, "duration", time.Now().Sub(start))
s.logger.Debug("request complete", "method", req.Method, "path", reqURL, "duration", time.Since(start))
}()
obj, err := s.auditHandler(handler)(resp, req)
@@ -524,7 +523,7 @@ func (s *HTTPServer) wrapNonJSON(handler func(resp http.ResponseWriter, req *htt
reqURL := req.URL.String()
start := time.Now()
defer func() {
s.logger.Debug("request complete", "method", req.Method, "path", reqURL, "duration", time.Now().Sub(start))
s.logger.Debug("request complete", "method", req.Method, "path", reqURL, "duration", time.Since(start))
}()
obj, err := s.auditNonJSONHandler(handler)(resp, req)
@@ -595,7 +594,7 @@ func setMeta(resp http.ResponseWriter, m *structs.QueryMeta) {
// setHeaders is used to set canonical response header fields
func setHeaders(resp http.ResponseWriter, headers map[string]string) {
for field, value := range headers {
resp.Header().Set(http.CanonicalHeaderKey(field), value)
resp.Header().Set(field, value)
}
}

View File

@@ -79,7 +79,7 @@ func (c *AgentInfoCommand) Run(args []string) int {
for _, key := range statsKeys {
c.Ui.Output(key)
statsData, _ := info.Stats[key]
statsData := info.Stats[key]
statsDataKeys := make([]string, len(statsData))
i := 0
for key := range statsData {

View File

@@ -97,7 +97,7 @@ func (c *MonitorCommand) Run(args []string) int {
// Query the node info and lookup prefix
if len(nodeID) == 1 {
c.Ui.Error(fmt.Sprintf("Node identifier must contain at least two characters."))
c.Ui.Error("Node identifier must contain at least two characters.")
return 1
}

View File

@@ -168,7 +168,7 @@ func (l *AllocExecCommand) Run(args []string) int {
// Query the allocation info
if len(allocID) == 1 {
l.Ui.Error(fmt.Sprintf("Alloc ID must contain at least two characters."))
l.Ui.Error("Alloc ID must contain at least two characters.")
return 1
}

View File

@@ -178,7 +178,7 @@ func (f *AllocFSCommand) Run(args []string) int {
}
// Query the allocation info
if len(allocID) == 1 {
f.Ui.Error(fmt.Sprintf("Alloc ID must contain at least two characters."))
f.Ui.Error("Alloc ID must contain at least two characters.")
return 1
}

View File

@@ -158,7 +158,7 @@ func (l *AllocLogsCommand) Run(args []string) int {
}
// Query the allocation info
if len(allocID) == 1 {
l.Ui.Error(fmt.Sprintf("Alloc ID must contain at least two characters."))
l.Ui.Error("Alloc ID must contain at least two characters.")
return 1
}

View File

@@ -68,7 +68,7 @@ func (c *AllocRestartCommand) Run(args []string) int {
// Query the allocation info
if len(allocID) == 1 {
c.Ui.Error(fmt.Sprintf("Alloc ID must contain at least two characters."))
c.Ui.Error("Alloc ID must contain at least two characters.")
return 1
}

View File

@@ -73,7 +73,7 @@ func (c *AllocSignalCommand) Run(args []string) int {
// Query the allocation info
if len(allocID) == 1 {
c.Ui.Error(fmt.Sprintf("Alloc ID must contain at least two characters."))
c.Ui.Error("Alloc ID must contain at least two characters.")
return 1
}

View File

@@ -149,7 +149,7 @@ func (c *AllocStatusCommand) Run(args []string) int {
// Query the allocation info
if len(allocID) == 1 {
c.Ui.Error(fmt.Sprintf("Identifier must contain at least two characters."))
c.Ui.Error("Identifier must contain at least two characters.")
return 1
}

View File

@@ -76,7 +76,7 @@ func (c *AllocStopCommand) Run(args []string) int {
// Query the allocation info
if len(allocID) == 1 {
c.Ui.Error(fmt.Sprintf("Alloc ID must contain at least two characters."))
c.Ui.Error("Alloc ID must contain at least two characters.")
return 1
}

View File

@@ -139,7 +139,7 @@ func (c *EvalStatusCommand) Run(args []string) int {
// Query the allocation info
if len(evalID) == 1 {
c.Ui.Error(fmt.Sprintf("Identifier must contain at least two characters."))
c.Ui.Error("Identifier must contain at least two characters.")
return 1
}

View File

@@ -255,7 +255,7 @@ func (c *JobPlanCommand) addPreemptions(resp *api.JobPlanResponse) {
c.Ui.Output(c.Colorize().Color("[bold][yellow]Preemptions:\n[reset]"))
if len(resp.Annotations.PreemptedAllocs) < preemptionDisplayThreshold {
var allocs []string
allocs = append(allocs, fmt.Sprintf("Alloc ID|Job ID|Task Group"))
allocs = append(allocs, "Alloc ID|Job ID|Task Group")
for _, alloc := range resp.Annotations.PreemptedAllocs {
allocs = append(allocs, fmt.Sprintf("%s|%s|%s", alloc.ID, alloc.JobID, alloc.TaskGroup))
}
@@ -284,7 +284,7 @@ func (c *JobPlanCommand) addPreemptions(resp *api.JobPlanResponse) {
// Show counts grouped by job ID if its less than a threshold
var output []string
if numJobs < preemptionDisplayThreshold {
output = append(output, fmt.Sprintf("Job ID|Namespace|Job Type|Preemptions"))
output = append(output, "Job ID|Namespace|Job Type|Preemptions")
for jobType, jobCounts := range allocDetails {
for jobId, count := range jobCounts {
output = append(output, fmt.Sprintf("%s|%s|%s|%d", jobId.id, jobId.namespace, jobType, count))
@@ -292,7 +292,7 @@ func (c *JobPlanCommand) addPreemptions(resp *api.JobPlanResponse) {
}
} else {
// Show counts grouped by job type
output = append(output, fmt.Sprintf("Job Type|Preemptions"))
output = append(output, "Job Type|Preemptions")
for jobType, jobCounts := range allocDetails {
total := 0
for _, count := range jobCounts {

View File

@@ -188,7 +188,7 @@ func (c *JobStatusCommand) Run(args []string) int {
if periodic && !parameterized {
if *job.Stop {
basic = append(basic, fmt.Sprintf("Next Periodic Launch|none (job stopped)"))
basic = append(basic, "Next Periodic Launch|none (job stopped)")
} else {
location, err := job.Periodic.GetLocation()
if err == nil {

View File

@@ -97,7 +97,7 @@ func (c *NodeConfigCommand) Run(args []string) int {
c.Ui.Error(fmt.Sprintf("Error updating server list: %s", err))
return 1
}
c.Ui.Output(fmt.Sprint("Updated server list"))
c.Ui.Output("Updated server list")
return 0
}

View File

@@ -223,7 +223,7 @@ func (c *NodeDrainCommand) Run(args []string) int {
// Check if node exists
if len(nodeID) == 1 {
c.Ui.Error(fmt.Sprintf("Identifier must contain at least two characters."))
c.Ui.Error("Identifier must contain at least two characters.")
return 1
}

View File

@@ -123,7 +123,7 @@ func (c *NodeEligibilityCommand) Run(args []string) int {
// Check if node exists
if len(nodeID) == 1 {
c.Ui.Error(fmt.Sprintf("Identifier must contain at least two characters."))
c.Ui.Error("Identifier must contain at least two characters.")
return 1
}

View File

@@ -239,7 +239,7 @@ func (c *NodeStatusCommand) Run(args []string) int {
}
}
if len(nodeID) == 1 {
c.Ui.Error(fmt.Sprintf("Identifier must contain at least two characters."))
c.Ui.Error("Identifier must contain at least two characters.")
return 1
}

View File

@@ -373,9 +373,7 @@ func (c *OperatorDebugCommand) Run(args []string) int {
c.serverIDs = append(c.serverIDs, member.Name)
}
} else {
for _, id := range argNodes(serverIDs) {
c.serverIDs = append(c.serverIDs, id)
}
c.serverIDs = append(c.serverIDs, argNodes(serverIDs)...)
}
serversFound := 0
@@ -590,7 +588,7 @@ func (c *OperatorDebugCommand) collectAgentHost(path, id string, client *api.Cli
if strings.Contains(err.Error(), structs.ErrPermissionDenied.Error()) {
// Drop a hint to help the operator resolve the error
c.Ui.Warn(fmt.Sprintf("Agent host retrieval requires agent:read ACL or enable_debug=true. See https://www.nomadproject.io/api-docs/agent#host for more information."))
c.Ui.Warn("Agent host retrieval requires agent:read ACL or enable_debug=true. See https://www.nomadproject.io/api-docs/agent#host for more information.")
}
return // exit on any error
}
@@ -630,7 +628,7 @@ func (c *OperatorDebugCommand) collectPprof(path, id string, client *api.Client)
// one permission failure before we bail.
// But lets first drop a hint to help the operator resolve the error
c.Ui.Warn(fmt.Sprintf("Pprof retrieval requires agent:write ACL or enable_debug=true. See https://www.nomadproject.io/api-docs/agent#agent-runtime-profiles for more information."))
c.Ui.Warn("Pprof retrieval requires agent:write ACL or enable_debug=true. See https://www.nomadproject.io/api-docs/agent#agent-runtime-profiles for more information.")
return // only exit on 403
}
} else {

View File

@@ -38,7 +38,7 @@ func (c *OperatorKeygenCommand) Run(_ []string) int {
return 1
}
if n != 32 {
c.Ui.Error(fmt.Sprintf("Couldn't read enough entropy. Generate more entropy!"))
c.Ui.Error("Couldn't read enough entropy. Generate more entropy!")
return 1
}

View File

@@ -171,7 +171,7 @@ func (c *OperatorKeyringCommand) handleKeyResponse(resp *api.KeyringResponse) {
out[0] = "Key"
i := 1
for k := range resp.Keys {
out[i] = fmt.Sprintf("%s", k)
out[i] = k
i = i + 1
}
c.Ui.Output(formatList(out))

View File

@@ -96,9 +96,7 @@ func (r *RecommendationApplyCommand) Run(args []string) int {
// Create a list of recommendations to apply.
ids := make([]string, len(args))
for i, id := range args {
ids[i] = id
}
copy(ids, args)
resp, _, err := client.Recommendations().Apply(ids, override)
if err != nil {

View File

@@ -93,9 +93,7 @@ func (r *RecommendationDismissCommand) Run(args []string) int {
// Create a list of recommendations to dismiss.
ids := make([]string, len(args))
for i, id := range args {
ids[i] = id
}
copy(ids, args)
_, err = client.Recommendations().Delete(ids, nil)
if err != nil {

View File

@@ -168,8 +168,5 @@ func (s scalingPolicyStubList) Less(i, j int) bool {
stringList := []string{iTarget, jTarget}
sort.Strings(stringList)
if stringList[0] == iTarget {
return true
}
return false
return stringList[0] == iTarget
}

View File

@@ -184,6 +184,6 @@ func (c *StatusCommand) logMultiMatchError(id string, matches map[contexts.Conte
}
c.Ui.Error(fmt.Sprintf("\n%s:", strings.Title(string(ctx))))
c.Ui.Error(fmt.Sprintf("%s", strings.Join(vers, ", ")))
c.Ui.Error(strings.Join(vers, ", "))
}
}

View File

@@ -182,6 +182,6 @@ func (c *UiCommand) logMultiMatchError(id string, matches map[contexts.Context][
}
c.Ui.Error(fmt.Sprintf("\n%s:", strings.Title(string(ctx))))
c.Ui.Error(fmt.Sprintf("%s", strings.Join(vers, ", ")))
c.Ui.Error(strings.Join(vers, ", "))
}
}

View File

@@ -52,9 +52,7 @@ func (c *VolumeDetachCommand) AutocompleteArgs() complete.Predictor {
if err != nil {
return []string{}
}
for _, match := range resp.Matches[contexts.Nodes] {
matches = append(matches, match)
}
matches = append(matches, resp.Matches[contexts.Nodes]...)
return matches
})
}