diff --git a/configuration/configuration.go b/configuration/configuration.go index 6fff2370..2407b004 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -149,7 +149,7 @@ func (c *Client) GetParser(transaction string) (*parser.Parser, error) { //AddParser adds parser to parser map func (c *Client) AddParser(transaction string) error { if transaction == "" { - return NewConfError(ErrValidationError, fmt.Sprintf("Not a valid transaction")) + return NewConfError(ErrValidationError, "Not a valid transaction") } _, ok := c.parsers[transaction] if ok { @@ -181,7 +181,7 @@ func (c *Client) AddParser(transaction string) error { //DeleteParser deletes parser from parsers map func (c *Client) DeleteParser(transaction string) error { if transaction == "" { - return NewConfError(ErrValidationError, fmt.Sprintf("Not a valid transaction")) + return NewConfError(ErrValidationError, "Not a valid transaction") } _, ok := c.parsers[transaction] if !ok { @@ -194,7 +194,7 @@ func (c *Client) DeleteParser(transaction string) error { //CommitParser commits transaction parser, deletes it from parsers map, and replaces master Parser func (c *Client) CommitParser(transaction string) error { if transaction == "" { - return NewConfError(ErrValidationError, fmt.Sprintf("Not a valid transaction")) + return NewConfError(ErrValidationError, "Not a valid transaction") } p, ok := c.parsers[transaction] if !ok { @@ -1018,7 +1018,7 @@ func (s *SectionParser) redispatch() interface{} { if d.Interval != nil { br.Interval = *d.Interval } - if d.NoOption == true { + if d.NoOption { d := "disabled" br.Enabled = &d } else { diff --git a/configuration/serivice.go b/configuration/service.go similarity index 99% rename from configuration/serivice.go rename to configuration/service.go index 220f8470..f9277d8c 100644 --- a/configuration/serivice.go +++ b/configuration/service.go @@ -344,7 +344,7 @@ func (s *Service) serverExists(server ServiceServer) bool { func (s *Service) setServer(server ServiceServer) error { for _, sNode := range s.nodes { - if sNode.disabled == true { + if sNode.disabled { sNode.modified = true sNode.disabled = false sNode.address = server.Address diff --git a/configuration/site.go b/configuration/site.go index 5ccd43f1..eb4bbc30 100644 --- a/configuration/site.go +++ b/configuration/site.go @@ -360,15 +360,11 @@ func (c *Client) EditSite(name string, data *models.Site, transactionID string, if f.Name == name { continue } - if _, ok := danglingBcks[f.DefaultBackend]; ok { - delete(danglingBcks, f.DefaultBackend) - } + delete(danglingBcks, f.DefaultBackend) _, ubs, err := c.GetBackendSwitchingRules(f.Name, t) if err == nil { for _, ub := range ubs { - if _, ok := danglingBcks[ub.Name]; ok { - delete(danglingBcks, ub.Name) - } + delete(danglingBcks, ub.Name) } } } diff --git a/configuration/transaction.go b/configuration/transaction.go index 3a47fc15..87a92df0 100644 --- a/configuration/transaction.go +++ b/configuration/transaction.go @@ -360,7 +360,7 @@ func (c *Client) createTransactionFiles(transactionID string) error { } } else { if !transDir.Mode().IsDir() { - return fmt.Errorf("Transaction dir %s is a file", c.TransactionDir) + return fmt.Errorf("transaction dir %s is a file", c.TransactionDir) } } diff --git a/misc/arrayutil.go b/misc/arrayutil.go index d8cd8242..a8e459f8 100644 --- a/misc/arrayutil.go +++ b/misc/arrayutil.go @@ -1,4 +1,3 @@ - // Copyright 2019 HAProxy Technologies // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/misc/stringutil.go b/misc/stringutil.go index bfbaac6f..dde6ef8a 100644 --- a/misc/stringutil.go +++ b/misc/stringutil.go @@ -59,13 +59,13 @@ func CamelCase(fieldName string, initCase bool) string { } } // special cases - n = strings.Replace(n, "Http", "HTTP", -1) - n = strings.Replace(n, "Uri", "URI", -1) - n = strings.Replace(n, "http", "HTTP", -1) - n = strings.Replace(n, "tcp", "TCP", -1) - n = strings.Replace(n, "Tcp", "TCP", -1) - n = strings.Replace(n, "Id", "ID", -1) - n = strings.Replace(n, "Tls", "TLS", -1) + n = strings.ReplaceAll(n, "Http", "HTTP") + n = strings.ReplaceAll(n, "Uri", "URI") + n = strings.ReplaceAll(n, "http", "HTTP") + n = strings.ReplaceAll(n, "tcp", "TCP") + n = strings.ReplaceAll(n, "Tcp", "TCP") + n = strings.ReplaceAll(n, "Id", "ID") + n = strings.ReplaceAll(n, "Tls", "TLS") return n } @@ -133,7 +133,7 @@ func DashCase(fieldName string) string { } n = strings.ToLower(n) // special case - n = strings.Replace(n, "httpuri", "http-uri", -1) + n = strings.ReplaceAll(n, "httpuri", "http-uri") return n } @@ -143,7 +143,7 @@ func ParseTimeout(tOut string) *int64 { v, _ = strconv.ParseInt(strings.TrimSuffix(tOut, "ms"), 10, 64) } else if strings.HasSuffix(tOut, "s") { v, _ = strconv.ParseInt(strings.TrimSuffix(tOut, "s"), 10, 64) - v = v * 1000 + v *= 1000 } else if strings.HasSuffix(tOut, "m") { v, _ = strconv.ParseInt(strings.TrimSuffix(tOut, "m"), 10, 64) v = v * 1000 * 60 @@ -166,7 +166,7 @@ func ParseSize(size string) *int64 { var v int64 if strings.HasSuffix(size, "k") { v, _ = strconv.ParseInt(strings.TrimSuffix(size, "k"), 10, 64) - v = v * 1024 + v *= 1024 } else if strings.HasSuffix(size, "m") { v, _ = strconv.ParseInt(strings.TrimSuffix(size, "m"), 10, 64) v = v * 1024 * 1024 @@ -195,7 +195,7 @@ func RandomString(n int) string { b := make([]rune, n) size := len(chars) for i := range b { - b[i] = chars[rand.Intn(size)] + b[i] = chars[rand.Intn(size)] //nolint:gosec } return string(b) } diff --git a/runtime/info.go b/runtime/info.go index 9e055b6d..a2fe196e 100644 --- a/runtime/info.go +++ b/runtime/info.go @@ -47,7 +47,7 @@ func parseInfo(info string, socketPath string) *models.ProcessInfoItem { data.Version = fields[3] case "2": d := strfmt.Date{} - err := d.Scan(strings.Replace(fields[3], "/", "-", -1)) + err := d.Scan(strings.ReplaceAll(fields[3], "/", "-")) if err == nil { data.ReleaseDate = d } diff --git a/runtime/runtime_client.go b/runtime/runtime_client.go index fa868a54..909afb78 100644 --- a/runtime/runtime_client.go +++ b/runtime/runtime_client.go @@ -101,7 +101,7 @@ func (c *Client) InitWithMasterSocket(masterSocketPath string, nbproc int) error nbproc = 1 } if masterSocketPath == "" { - return fmt.Errorf("Master socket not configured") + return fmt.Errorf("master socket not configured") } c.runtimes = make([]SingleRuntime, nbproc) for i := 1; i <= nbproc; i++ { diff --git a/runtime/runtime_single_client.go b/runtime/runtime_single_client.go index 31f76757..a274cfbc 100644 --- a/runtime/runtime_single_client.go +++ b/runtime/runtime_single_client.go @@ -91,7 +91,7 @@ func (s *SingleRuntime) readFromSocket(command string) (string, error) { buf := make([]byte, bufferSize) var data strings.Builder for { - n, err := api.Read(buf[:]) + n, err := api.Read(buf) if err != nil { break } @@ -121,7 +121,7 @@ func (s *SingleRuntime) readFromSocketClean(command string) (string, error) { buf := make([]byte, 1024) var data strings.Builder for { - n, err := api.Read(buf[:]) + n, err := api.Read(buf) if err != nil { break } @@ -170,11 +170,11 @@ func (s *SingleRuntime) ExecuteWithResponse(command string) (string, error) { func (s *SingleRuntime) executeRaw(command string, retry int) (string, error) { response := make(chan TaskResponse) - Task := Task{ + task := Task{ command: command, response: response, } - s.jobs <- Task + s.jobs <- task select { case rsp := <-response: if rsp.err != nil && retry > 0 {