Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add golangci-lint #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Lint

on:
push:
branches:
- master
pull_request:
branches:
- master

defaults:
run:
shell: bash

concurrency:
group: ${{ github.ref_name }}-lint
cancel-in-progress: true

jobs:
lint:
name: Go Lint
runs-on: ubuntu-24.04
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Golang Environment
uses: actions/setup-go@v5
with:
go-version: stable

- name: Lint Go
uses: golangci/golangci-lint-action@v6

actionlint:
name: Actionlint
runs-on: ubuntu-24.04
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Lint Actions
uses: reviewdog/action-actionlint@v1
with:
actionlint_flags: -shellcheck ""
90 changes: 90 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
linters-settings:
misspell:
locale: US
revive:
ignore-generated-header: true
rules:
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: empty-block
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: exported
- name: increment-decrement
- name: indent-error-flow
- name: package-comments
- name: range
- name: receiver-naming
- name: redefines-builtin-id
- name: superfluous-else
- name: time-naming
- name: unexported-return
- name: unreachable-code
- name: var-declaration
- name: var-naming
govet:
enable-all: true
linters:
enable:
- asasalint
- asciicheck
- bidichk
- contextcheck
- copyloopvar
- dupword
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- fatcontext
- forcetypeassert
- gocheckcompilerdirectives
- gochecksumtype
- gocritic
- godot
- gofmt
- gofumpt
- goimports
- gosec
- gosimple
- gosmopolitan
- govet
- ineffassign
- intrange
- makezero
- misspell
- musttag
- nilerr
- noctx
- nolintlint
- paralleltest
- perfsprint
- prealloc
- predeclared
- reassign
- revive
- staticcheck
- stylecheck
- tagalign
- tenv
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign
- whitespace
# - wrapcheck
disable-all: true
issues:
max-issues-per-linter: 0
max-same-issues: 0
run:
timeout: 5m
30 changes: 14 additions & 16 deletions log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

// DEBUG

// DebugWithContext logs on debug level and trace based on the context span if it exists
// DebugWithContext logs on debug level and trace based on the context span if it exists.
func DebugWithContext(ctx context.Context, log string, fields ...zapcore.Field) {
DebugWithSpan(opentracing.SpanFromContext(ctx), log, fields...)
}
Expand All @@ -23,14 +23,14 @@
logSpan(span, log, fields...)
}

// Debug logs on debug level
// Debug logs on debug level.
func Debug(log string, fields ...zapcore.Field) {
zap.L().Debug(log, fields...)
}

// INFO

// InfoWithContext logs on info level and trace based on the context span if it exists
// InfoWithContext logs on info level and trace based on the context span if it exists.
func InfoWithContext(ctx context.Context, log string, fields ...zapcore.Field) {
InfoWithSpan(opentracing.SpanFromContext(ctx), log, fields...)
}
Expand All @@ -39,17 +39,16 @@
func InfoWithSpan(span opentracing.Span, log string, fields ...zapcore.Field) {
Info(log, fields...)
logSpan(span, log, fields...)

}

// Info logs on info level
// Info logs on info level.
func Info(log string, fields ...zapcore.Field) {
zap.L().Info(log, fields...)
}

// WARN

// WarnWithContext logs on warn level and trace based on the context span if it exists
// WarnWithContext logs on warn level and trace based on the context span if it exists.
func WarnWithContext(ctx context.Context, log string, fields ...zapcore.Field) {
WarnWithSpan(opentracing.SpanFromContext(ctx), log, fields...)
}
Expand All @@ -58,17 +57,16 @@
func WarnWithSpan(span opentracing.Span, log string, fields ...zapcore.Field) {
Warn(log, fields...)
logSpan(span, log, fields...)

}

// Warn logs on warn level
// Warn logs on warn level.
func Warn(log string, fields ...zapcore.Field) {
zap.L().Warn(log, fields...)
}

// ERROR

// ErrorWithContext logs on error level and trace based on the context span if it exists
// ErrorWithContext logs on error level and trace based on the context span if it exists.
func ErrorWithContext(ctx context.Context, log string, fields ...zapcore.Field) {
ErrorWithSpan(opentracing.SpanFromContext(ctx), log, fields...)
}
Expand All @@ -79,14 +77,14 @@
logSpan(span, log, fields...)
}

// Error logs on error level
// Error logs on error level.
func Error(log string, fields ...zapcore.Field) {
zap.L().Error(log, fields...)
}

// DPANIC

// DPanicWithContext logs on dPanic level and trace based on the context span if it exists
// DPanicWithContext logs on dPanic level and trace based on the context span if it exists.
func DPanicWithContext(ctx context.Context, log string, fields ...zapcore.Field) {
DPanicWithSpan(opentracing.SpanFromContext(ctx), log, fields...)
}
Expand All @@ -97,14 +95,14 @@
DPanic(log, fields...)
}

// DPanic logs on dPanic level
// DPanic logs on dPanic level.
func DPanic(log string, fields ...zapcore.Field) {
zap.L().DPanic(log, fields...)
}

// PANIC

// PanicWithContext logs on panic level and trace based on the context span if it exists
// PanicWithContext logs on panic level and trace based on the context span if it exists.
func PanicWithContext(ctx context.Context, log string, fields ...zapcore.Field) {
PanicWithSpan(opentracing.SpanFromContext(ctx), log, fields...)
}
Expand All @@ -115,12 +113,12 @@
Panic(log, fields...)
}

// Panic logs on panic level
// Panic logs on panic level.
func Panic(log string, fields ...zapcore.Field) {
zap.L().Panic(log, fields...)
}

// FatalWithContext logs on fatal level and trace based on the context span if it exists
// FatalWithContext logs on fatal level and trace based on the context span if it exists.
func FatalWithContext(ctx context.Context, log string, fields ...zapcore.Field) {
FatalWithSpan(opentracing.SpanFromContext(ctx), log, fields...)
}
Expand All @@ -131,7 +129,7 @@
Fatal(log, fields...)
}

// Fatal logs on fatal level
// Fatal logs on fatal level.
func Fatal(log string, fields ...zapcore.Field) {
zap.L().Fatal(log, fields...)
}
Expand All @@ -140,10 +138,10 @@
if span != nil {
opentracingFields := make([]opentracinglog.Field, len(fields)+1)
if log != "" {
opentracingFields = append(opentracingFields, opentracinglog.String("event", log))

Check failure on line 141 in log/log.go

View workflow job for this annotation

GitHub Actions / Go Lint

append to slice `opentracingFields` with non-zero initialized length (makezero)
}
if len(fields) > 0 {
opentracingFields = append(opentracingFields, utils.ZapFieldsToOpentracing(fields...)...)

Check failure on line 144 in log/log.go

View workflow job for this annotation

GitHub Actions / Go Lint

append to slice `opentracingFields` with non-zero initialized length (makezero)
}
span.LogFields(opentracingFields...)
}
Expand Down
1 change: 0 additions & 1 deletion utils/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
// input Zap field.
func ZapFieldToOpentracing(zapField zapcore.Field) opentracinglog.Field {
switch zapField.Type {

case zapcore.BoolType:
val := false
if zapField.Integer >= 1 {
Expand All @@ -33,25 +32,25 @@
}
return opentracinglog.Bool(zapField.Key, val)
case zapcore.Float32Type:
return opentracinglog.Float32(zapField.Key, math.Float32frombits(uint32(zapField.Integer)))

Check failure on line 35 in utils/fields.go

View workflow job for this annotation

GitHub Actions / Go Lint

G115: integer overflow conversion int64 -> uint32 (gosec)
case zapcore.Float64Type:
return opentracinglog.Float64(zapField.Key, math.Float64frombits(uint64(zapField.Integer)))

Check failure on line 37 in utils/fields.go

View workflow job for this annotation

GitHub Actions / Go Lint

G115: integer overflow conversion int64 -> uint64 (gosec)
case zapcore.Int64Type:
return opentracinglog.Int64(zapField.Key, int64(zapField.Integer))

Check failure on line 39 in utils/fields.go

View workflow job for this annotation

GitHub Actions / Go Lint

unnecessary conversion (unconvert)
case zapcore.Int32Type:
return opentracinglog.Int32(zapField.Key, int32(zapField.Integer))

Check failure on line 41 in utils/fields.go

View workflow job for this annotation

GitHub Actions / Go Lint

G115: integer overflow conversion int64 -> int32 (gosec)
case zapcore.StringType:
return opentracinglog.String(zapField.Key, zapField.String)
case zapcore.StringerType:
return opentracinglog.String(zapField.Key, zapField.Interface.(fmt.Stringer).String())

Check failure on line 45 in utils/fields.go

View workflow job for this annotation

GitHub Actions / Go Lint

type assertion must be checked (forcetypeassert)
case zapcore.Uint64Type:
return opentracinglog.Uint64(zapField.Key, uint64(zapField.Integer))

Check failure on line 47 in utils/fields.go

View workflow job for this annotation

GitHub Actions / Go Lint

G115: integer overflow conversion int64 -> uint64 (gosec)
case zapcore.Uint32Type:
return opentracinglog.Uint32(zapField.Key, uint32(zapField.Integer))

Check failure on line 49 in utils/fields.go

View workflow job for this annotation

GitHub Actions / Go Lint

G115: integer overflow conversion int64 -> uint32 (gosec)
case zapcore.DurationType:
return opentracinglog.String(zapField.Key, time.Duration(zapField.Integer).String())
case zapcore.ErrorType:
return opentracinglog.Error(zapField.Interface.(error))

Check failure on line 53 in utils/fields.go

View workflow job for this annotation

GitHub Actions / Go Lint

type assertion must be checked (forcetypeassert)
default:
return opentracinglog.Object(zapField.Key, zapField.Interface)
}
Expand Down
2 changes: 0 additions & 2 deletions utils/fields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func (s stringer) String() string {
}

func TestFieldsConversion(t *testing.T) {

TestData := []struct {
ZapField zapcore.Field
OpenTracingField opentracinglog.Field
Expand Down Expand Up @@ -97,5 +96,4 @@ func TestFieldsConversion(t *testing.T) {
t.Errorf("Expected same value. Got %s but expected %s", result.Value(), data.OpenTracingField.Value())
}
}

}