Skip to content

Commit

Permalink
Add comments as suggested by SonarCloud
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaasuni-vonage committed Jan 27, 2023
1 parent 52e1275 commit 93711fe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
12 changes: 7 additions & 5 deletions pkg/httpserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,27 +141,29 @@ func (c *config) validate() error {

// validateAddr checks if a http server bind address is valid.
func validateAddr(addr string) error {
addrErr := fmt.Errorf("invalid http server address: %s", addr)

if !strings.Contains(addr, ":") {
return fmt.Errorf("invalid http server address: %s", addr)
return addrErr
}

parts := strings.Split(addr, ":")
if len(parts) != 2 {
return fmt.Errorf("invalid http server address: %s", addr)
return addrErr
}

port := parts[1]
if port == "" {
return fmt.Errorf("invalid http server address: %s", addr)
return addrErr
}

portInt, err := strconv.Atoi(port)
if err != nil {
return fmt.Errorf("invalid http server address: %s", addr)
return addrErr
}

if portInt < 1 || portInt > math.MaxUint16 {
return fmt.Errorf("invalid http server address: %s", addr)
return addrErr
}

return nil
Expand Down
1 change: 1 addition & 0 deletions pkg/logging/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type config struct {
}

func defaultConfig() *config {
// Return default configuration fields.
return &config{
fields: make([]zap.Field, 0, 3),
format: JSONFormat,
Expand Down
6 changes: 5 additions & 1 deletion pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (c *Default) InstrumentRoundTripper(next http.RoundTripper) http.RoundTripp

// MetricsHandlerFunc returns an http handler function.
func (c *Default) MetricsHandlerFunc() http.HandlerFunc {
// Returns "OK" by default.
return func(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte(`OK`)) }
}

Expand All @@ -60,4 +61,7 @@ func (c *Default) IncLogLevelCounter(level string) {}
func (c *Default) IncErrorCounter(task, operation, code string) {}

// Close method.
func (c *Default) Close() error { return nil }
func (c *Default) Close() error {
// Do nothing by default.
return nil
}

0 comments on commit 93711fe

Please sign in to comment.