Skip to content

Commit

Permalink
fix: lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
franklinkim committed Nov 18, 2024
1 parent 1e79f55 commit 74d3162
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 21 deletions.
5 changes: 2 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,13 @@ linters:
- bodyclose # checks whether HTTP response body is closed successfully [fast: false, auto-fix: false]
#- containedctx # containedctx is a linter that detects struct contained context.Context field [fast: false, auto-fix: false]
- contextcheck # check whether the function uses a non-inherited context [fast: false, auto-fix: false]
#- copyloopvar # (go >= 1.22) copyloopvar is a linter detects places where loop variables are copied [fast: true, auto-fix: false]
- copyloopvar # (go >= 1.22) copyloopvar is a linter detects places where loop variables are copied [fast: true, auto-fix: false]
- decorder # check declaration order and count of types, constants, variables and functions [fast: true, auto-fix: false]
- durationcheck # check for two durations multiplied together [fast: false, auto-fix: false]
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and reports occations, where the check for the returned error can be omitted. [fast: false, auto-fix: false]
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`. [fast: false, auto-fix: false]
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. [fast: false, auto-fix: false]
- exhaustive # check exhaustiveness of enum switch statements [fast: false, auto-fix: false]
- exportloopref # checks for pointers to enclosing loop variables [fast: false, auto-fix: false]
#- forbidigo # Forbids identifiers [fast: false, auto-fix: false]
- forcetypeassert # finds forced type assertions [fast: true, auto-fix: false]
- gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid. [fast: true, auto-fix: false]
Expand All @@ -136,7 +135,7 @@ linters:
- grouper # Analyze expression groups. [fast: true, auto-fix: false]
- importas # Enforces consistent import aliases [fast: false, auto-fix: false]
#- inamedparam # reports interfaces with unnamed method parameters [fast: true, auto-fix: false]
#- intrange # (go >= 1.22) intrange is a linter to find places where for loops could make use of an integer range. [fast: true, auto-fix: false]
- intrange # (go >= 1.22) intrange is a linter to find places where for loops could make use of an integer range. [fast: true, auto-fix: false]
#- loggercheck # (logrlint) Checks key value pairs for common logger libraries (kitlog,klog,logr,zap). [fast: false, auto-fix: false]
- makezero # Finds slice declarations with non-zero initial length [fast: false, auto-fix: false]
- misspell # Finds commonly misspelled English words [fast: true, auto-fix: true]
Expand Down
6 changes: 3 additions & 3 deletions net/gotsrpc/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ type Error string

// Common errors
const (
ErrorNotFound Error = "notFound" //nolint:errname
ErrorForbidden Error = "forbidden" //nolint:errname
ErrorPermissionDenied Error = "permissionDenied" //nolint:errname
ErrorNotFound Error = "notFound"
ErrorForbidden Error = "forbidden"
ErrorPermissionDenied Error = "permissionDenied"
)

// NewError returns a pointer error
Expand Down
4 changes: 2 additions & 2 deletions net/http/cookie/domainprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewDomainProvider(opts ...DomainProviderOption) DomainProvider {
return func(r *http.Request) (string, error) {
domain := keelhttp.GetRequestDomain(r)

if options.Domains == nil || len(options.Domains) == 0 {
if len(options.Domains) == 0 {
return domain, nil
}

Expand All @@ -58,7 +58,7 @@ func NewDomainProvider(opts ...DomainProviderOption) DomainProvider {
}
}

if options.Domains != nil && len(options.Domains) > 0 {
if len(options.Domains) > 0 {
for _, value := range options.Domains {
// foo.com = foo.com
// foo.com = *.foo.com
Expand Down
8 changes: 4 additions & 4 deletions net/http/roundtripware/circuitbreaker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func TestCircuitBreakerInterval(t *testing.T) {
)

// send exactly 3 requests (lower than the maximum amount of allowed consecutive failures)
for i := 0; i < 3; i++ {
for range 3 {
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, svr.URL, nil)
require.NoError(t, err)
resp, err := client.Do(req)
Expand All @@ -310,7 +310,7 @@ func TestCircuitBreakerInterval(t *testing.T) {

// now we should be able to send 3 more requests without triggering the circuit breaker (last request should finally
// trigger the circuit breaker, but the error will not yet be a circuitbreaker error)
for i := 0; i <= 3; i++ {
for range 4 {
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, svr.URL, nil)
require.NoError(t, err)
resp, err := client.Do(req)
Expand Down Expand Up @@ -362,7 +362,7 @@ func TestCircuitBreakerIgnore(t *testing.T) {

// send 4 requests (higher than the maximum amount of allowed consecutive failures), but they are ignored
// -> circuit breaker should remain open
for i := 0; i < 4; i++ {
for range 4 {
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, svr.URL, nil)
require.NoError(t, err)
resp, err := client.Do(req)
Expand Down Expand Up @@ -394,7 +394,7 @@ func TestCircuitBreakerTimeout(t *testing.T) {

// send 4 requests (more than the maximum amount of allowed consecutive failures)
// -> circuit breaker should change to open state
for i := 0; i < 4; i++ {
for range 4 {
ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)

req, err := http.NewRequestWithContext(ctx, http.MethodGet, svr.URL, nil)
Expand Down
2 changes: 1 addition & 1 deletion net/stream/jetstream/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (s *Stream) initNatsOptions() {
s.l.Error("nats disconnected error", log.FError(err))

var errRetry error
for i := 0; i < s.reconnectMaxRetries; i++ {
for range s.reconnectMaxRetries {
errRetry = s.connect()
if errRetry != nil {
s.l.Error("nats reconnect failed", log.FError(errRetry))
Expand Down
1 change: 0 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ func (s *Server) Readme() string {
func (s *Server) startService(services ...Service) {
c := make(chan struct{}, 1)
for _, value := range services {
value := value
s.g.Go(func() error {
c <- struct{}{}
if err := value.Start(s.ctx); errors.Is(err, http.ErrServerClosed) {
Expand Down
8 changes: 4 additions & 4 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (s *KeelTestSuite) TestServiceHTTPZap() {
s.Run("default", func() {
if statusCode, body, err := s.httpGet("http://localhost:9100/log"); s.NoError(err) {
s.Equal(http.StatusOK, statusCode)
s.Equal(`{"level":"info","disableCaller":true,"disableStacktrace":true}`, body)
s.JSONEq(`{"level":"info","disableCaller":true,"disableStacktrace":true}`, body)
}
if statusCode, _, err := s.httpGet("http://localhost:55000/log/info"); s.NoError(err) {
s.Equal(http.StatusOK, statusCode)
Expand All @@ -111,7 +111,7 @@ func (s *KeelTestSuite) TestServiceHTTPZap() {
s.Run("set debug level", func() {
if statusCode, body, err := s.httpPut("http://localhost:9100/log", `{"level":"debug"}`); s.NoError(err) {
s.Equal(http.StatusOK, statusCode)
s.Equal(`{"level":"debug","disableCaller":true,"disableStacktrace":true}`, body)
s.JSONEq(`{"level":"debug","disableCaller":true,"disableStacktrace":true}`, body)
}
if statusCode, _, err := s.httpGet("http://localhost:55000/log/info"); s.NoError(err) {
s.Equal(http.StatusOK, statusCode)
Expand All @@ -124,7 +124,7 @@ func (s *KeelTestSuite) TestServiceHTTPZap() {
s.Run("enable caller", func() {
if statusCode, body, err := s.httpPut("http://localhost:9100/log", `{"disableCaller":false}`); s.NoError(err) {
s.Equal(http.StatusOK, statusCode)
s.Equal(`{"level":"debug","disableCaller":false,"disableStacktrace":true}`, body)
s.JSONEq(`{"level":"debug","disableCaller":false,"disableStacktrace":true}`, body)
}
if statusCode, _, err := s.httpGet("http://localhost:55000/log/error"); s.NoError(err) {
s.Equal(http.StatusOK, statusCode)
Expand All @@ -134,7 +134,7 @@ func (s *KeelTestSuite) TestServiceHTTPZap() {
s.Run("enable stacktrace", func() {
if statusCode, body, err := s.httpPut("http://localhost:9100/log", `{"disableStacktrace":false}`); s.NoError(err) {
s.Equal(http.StatusOK, statusCode)
s.Equal(`{"level":"debug","disableCaller":false,"disableStacktrace":false}`, body)
s.JSONEq(`{"level":"debug","disableCaller":false,"disableStacktrace":false}`, body)
}
if statusCode, _, err := s.httpGet("http://localhost:55000/log/error"); s.NoError(err) {
s.Equal(http.StatusOK, statusCode)
Expand Down
3 changes: 1 addition & 2 deletions service/goroutine.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ func (s *GoRoutine) Start(ctx context.Context) error {
s.cancelLock.Lock()
s.cancel = cancel
s.cancelLock.Unlock()
for i := 0; i < s.parallel; i++ {
i := i
for i := range s.parallel {
l := log.WithAttributes(s.l, log.KeelServiceInstKey.Int(i))
s.wg.Go(func() error {
return s.handler(ctx, l)
Expand Down
2 changes: 1 addition & 1 deletion telemetry/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (l Logger) Init(info logr.RuntimeInfo) {
}

func (l Logger) Enabled(level int) bool {
return log.AtomicLevel().Enabled(zapcore.Level(-1 * level))
return log.AtomicLevel().Enabled(zapcore.Level(-1 * level)) //nolint:gosec
}

func (l Logger) Info(level int, msg string, keysAndValues ...interface{}) {
Expand Down

0 comments on commit 74d3162

Please sign in to comment.