Skip to content

Commit

Permalink
Add golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacome committed Dec 4, 2024
1 parent 65beb53 commit 598e062
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 19 deletions.
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 @@ import (

// 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 @@ func DebugWithSpan(span opentracing.Span, log string, fields ...zapcore.Field) {
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 InfoWithContext(ctx context.Context, log string, fields ...zapcore.Field) {
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 WarnWithContext(ctx context.Context, log string, fields ...zapcore.Field) {
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 @@ func ErrorWithSpan(span opentracing.Span, log string, fields ...zapcore.Field) {
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 @@ func DPanicWithSpan(span opentracing.Span, log string, fields ...zapcore.Field)
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 @@ func PanicWithSpan(span opentracing.Span, log string, fields ...zapcore.Field) {
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 @@ func FatalWithSpan(span opentracing.Span, log string, fields ...zapcore.Field) {
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 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 @@ func ZapFieldsToOpentracing(zapFields ...zapcore.Field) []opentracinglog.Field {
// input Zap field.
func ZapFieldToOpentracing(zapField zapcore.Field) opentracinglog.Field {
switch zapField.Type {

case zapcore.BoolType:
val := false
if zapField.Integer >= 1 {
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())
}
}

}

0 comments on commit 598e062

Please sign in to comment.