Skip to content

Commit

Permalink
CLEANUP/MINOR: resolve some linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
oktalz committed Dec 9, 2020
1 parent e9c72a8 commit 51acd2a
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 30 deletions.
8 changes: 4 additions & 4 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion configuration/serivice.go → configuration/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions configuration/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion configuration/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
1 change: 0 additions & 1 deletion misc/arrayutil.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// Copyright 2019 HAProxy Technologies
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
22 changes: 11 additions & 11 deletions misc/stringutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion runtime/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/runtime_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++ {
Expand Down
8 changes: 4 additions & 4 deletions runtime/runtime_single_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 51acd2a

Please sign in to comment.