Skip to content

Commit

Permalink
chore: Format with goimports and metalinter
Browse files Browse the repository at this point in the history
  • Loading branch information
laynax committed Oct 13, 2022
1 parent 3aabb65 commit 7f1ce3f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
13 changes: 7 additions & 6 deletions pkg/interceptors/database_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"context"

grpcmiddleware "github.com/grpc-ecosystem/go-grpc-middleware"
"google.golang.org/grpc"
"gorm.io/gorm"

sdkdatabasecontext "github.com/scribd/go-sdk/pkg/context/database"
sdkloggercontext "github.com/scribd/go-sdk/pkg/context/logger"
sdklogger "github.com/scribd/go-sdk/pkg/logger"
"google.golang.org/grpc"
"gorm.io/gorm"
)

// DatabaseLoggingUnaryServerInterceptor returns a unary server interceptor.
Expand All @@ -33,9 +34,9 @@ func DatabaseLoggingUnaryServerInterceptor() grpc.UnaryServerInterceptor {
}

newDB := db.Session(&gorm.Session{
Logger: sdklogger.NewGormLogger(l),
Logger: sdklogger.NewGormLogger(l),
Context: ctx,
NewDB: true,
NewDB: true,
})

newCtx := sdkdatabasecontext.ToContext(ctx, newDB)
Expand Down Expand Up @@ -68,9 +69,9 @@ func DatabaseLoggingStreamServerInterceptor() grpc.StreamServerInterceptor {
streamCtx := stream.Context()

newDB := db.Session(&gorm.Session{
Logger: sdklogger.NewGormLogger(l),
Logger: sdklogger.NewGormLogger(l),
Context: streamCtx,
NewDB: true,
NewDB: true,
})

newCtx := sdkdatabasecontext.ToContext(streamCtx, newDB)
Expand Down
8 changes: 4 additions & 4 deletions pkg/interceptors/database_logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import (
"path"
"testing"

sdktesting "github.com/scribd/go-sdk/pkg/testing"
"github.com/scribd/go-sdk/pkg/logger"
"github.com/scribd/go-sdk/pkg/testing/testproto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
Expand All @@ -21,6 +18,10 @@ import (
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/mocktracer"
"gorm.io/driver/sqlite"
"gorm.io/gorm"

"github.com/scribd/go-sdk/pkg/logger"
sdktesting "github.com/scribd/go-sdk/pkg/testing"
"github.com/scribd/go-sdk/pkg/testing/testproto"
)

type TestRecord struct {
Expand Down Expand Up @@ -194,7 +195,6 @@ func checkGormLoggerFields(t *testing.T, fields map[string]interface{}) {
assert.True(t, ok, "%s not found in log fields", logger.GormTraceFieldKey)
assert.NotEmpty(t, dbFields)


assert.NotEmpty(t, dbFields["elapsed_seconds"])
assert.NotEmpty(t, dbFields["affected_rows"])
assert.NotEmpty(t, dbFields["sql"])
Expand Down
2 changes: 1 addition & 1 deletion pkg/logger/gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (g gormLogger) Trace(ctx context.Context, begin time.Time, fc func() (strin
tracingLogger := g.logger.WithFields(Fields{
GormTraceFieldKey: Fields{
"elapsed_seconds": time.Since(begin).Seconds(),
"affected_rows": rows,
"affected_rows": rows,
"sql": sql,
},
})
Expand Down
3 changes: 2 additions & 1 deletion pkg/middleware/database_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package middleware
import (
"net/http"

"gorm.io/gorm"

sdkdatabasecontext "github.com/scribd/go-sdk/pkg/context/database"
sdkloggercontext "github.com/scribd/go-sdk/pkg/context/logger"
sdklogger "github.com/scribd/go-sdk/pkg/logger"
"gorm.io/gorm"
)

// DatabaseLoggingMiddleware wraps an instantiated sdk.Logger that will be injected
Expand Down
4 changes: 2 additions & 2 deletions pkg/tracking/sentry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package tracking

import (
"errors"
"io/ioutil"
"io"
"testing"

"github.com/getsentry/sentry-go"
Expand Down Expand Up @@ -74,7 +74,7 @@ func TestSentryHookManualTag(t *testing.T) {
func newMockLogger(hook *Hook) *logrus.Logger {
logger := logrus.New()

logger.SetOutput(ioutil.Discard)
logger.SetOutput(io.Discard)
logger.Hooks.Add(hook)

return logger
Expand Down

0 comments on commit 7f1ce3f

Please sign in to comment.