Skip to content

Commit d454d32

Browse files
committed
linter fixes
1 parent d211587 commit d454d32

File tree

16 files changed

+44
-23
lines changed

16 files changed

+44
-23
lines changed

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ skip-files:
1414
linters:
1515
enable-all: true
1616
disable:
17-
- fatcontext
1817
- nlreturn
1918
- wrapcheck
2019
- tagliatelle

context/keys/keys.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import (
66
"strings"
77
)
88

9-
type ContextKey rune
9+
type (
10+
ContextKey rune
11+
ContextStr string
12+
)
1013

1114
const (
1215
CtxTraceID ContextKey = iota
@@ -17,8 +20,8 @@ const (
1720
LogInfo
1821
RequestLogID
1922

20-
RequestIDStr = "X-Request-Id"
21-
IPAddressStr = "IP-Address"
23+
RequestIDStr ContextStr = "X-Request-Id"
24+
IPAddressStr ContextStr = "IP-Address"
2225
)
2326

2427
func GetAsString(ctx context.Context, key any) string {

db/conn.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func NewConn(ctx context.Context) *pgx.Conn {
2121

2222
// NewConnFromConfig is constructor for *pgx.Conn
2323
func NewConnFromConfig(ctx context.Context, pgConfig *pgx.ConnConfig) *pgx.Conn {
24+
//nolint:contextcheck
2425
logger := logger.NewComponentLogger(context.TODO(), pkgName)
2526

2627
return newConn(ctx, pgConfig, logger)

db/db.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//nolint:gochecknoglobals
12
package db
23

34
import (

db/dbtests/db_fixture.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import (
99
"github.com/webdevelop-pro/go-common/db"
1010
)
1111

12+
type contextKey string
13+
14+
const dbKey contextKey = "db"
15+
1216
type Fixture struct {
1317
table string
1418
filePath string
@@ -71,7 +75,7 @@ func (f FixturesManager) CleanAndApply() error {
7175
}
7276

7377
func (f FixturesManager) SetCTX(ctx context.Context) context.Context {
74-
return context.WithValue(ctx, "db", f.db)
78+
return context.WithValue(ctx, dbKey, f.db)
7579
}
7680

7781
func (f FixturesManager) Clean(table string) error {

db/dbtests/tests.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ const (
1818
)
1919

2020
func getDBPool(t tests.TestContext) *db.DB {
21-
return t.Ctx.Value("db").(*db.DB)
21+
//nolint:forcetypeassert
22+
return t.Ctx.Value(dbKey).(*db.DB)
2223
}
2324

2425
func RawSQL(query string) tests.SomeAction {

db/pool.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//nolint:gochecknoglobals
21
package db
32

43
import (

docker/go.mod

Lines changed: 0 additions & 3 deletions
This file was deleted.

docker/go.sum

Whitespace-only changes.

make.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,18 @@ install)
7676
;;
7777

7878
lint)
79-
golangci-lint -c .golangci.yml run $2 $3
79+
dirlist=`ls`
80+
for ddir in $dirlist[@]
81+
do
82+
if [ -d $ddir ]
83+
then
84+
if [ -f "$ddir/go.mod" ]; then
85+
cd $ddir
86+
golangci-lint -c ../.golangci.yml run --fix $2 $3
87+
cd ../
88+
fi
89+
fi
90+
done
8091
;;
8192

8293
test)

misc/httputils/httputils.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ type Request struct {
2020
Method, Path string
2121
Body []byte
2222
Headers map[string]string
23-
Ctx context.Context
2423
}
2524

2625
// CreateDefaultRequest default json request
27-
func CreateDefaultRequest(req Request) (*http.Request, error) {
26+
func CreateDefaultRequest(ctx context.Context, req Request) (*http.Request, error) {
2827
if req.Port != "" {
2928
req.Host = net.JoinHostPort(req.Host, req.Port)
3029
}
3130
if req.Scheme == "" {
3231
req.Scheme = "http"
3332
}
3433

35-
res, err := http.NewRequest(
34+
res, err := http.NewRequestWithContext(
35+
ctx,
3636
req.Method,
3737
fmt.Sprintf("%s://%s%s", req.Scheme, req.Host, req.Path),
3838
bytes.NewBuffer((req.Body)),
@@ -41,7 +41,6 @@ func CreateDefaultRequest(req Request) (*http.Request, error) {
4141
return res, errors.Wrapf(err, "cannot create new request")
4242
}
4343

44-
res = res.WithContext(req.Ctx)
4544
res.Header.Add("Content-Type", "application/json")
4645

4746
for key, value := range req.Headers {

queue/pclient/tests.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import (
77
"github.com/webdevelop-pro/go-common/tests"
88
)
99

10+
type contextKey string
11+
12+
const ctxKey contextKey = "db"
13+
1014
func getClient(t tests.TestContext) *Client {
15+
//nolint:forcetypeassert
1116
return t.Ctx.Value(pkgName).(*Client)
1217
}
1318

@@ -18,12 +23,14 @@ func SendPubSubEvent(topic string, body any, attr map[string]string) tests.SomeA
1823
}
1924
}
2025

26+
/*
2127
func CheckIfMsgRead(topic string, body any) tests.SomeAction {
2228
return func(t tests.TestContext) error {
2329
// _, err := getClient(t).PublishToTopic(context.Background(), topic, body, attr)
2430
return nil
2531
}
2632
}
33+
*/
2734

2835
type Fixture struct {
2936
topic string
@@ -66,7 +73,7 @@ func (pubSubF FixturesManager) CleanAndApply() error {
6673
}
6774

6875
func (pubSubF FixturesManager) SetCTX(ctx context.Context) context.Context {
69-
return context.WithValue(ctx, "pubsub", pubSubF.client)
76+
return context.WithValue(ctx, ctxKey, pubSubF.client)
7077
}
7178

7279
func (pubSubF FixturesManager) Clean(topic string, subscription string) error {

response/http.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
// BadRequest shortcut to return http.StatusBadRequest with custom error and msg
1010
func BadRequest(err error, msg string) Error {
1111
if err == nil {
12-
//nolint:goerr113
1312
err = errors.New("")
1413
}
1514
finalMsg := map[string][]string{"__error__": {msg}}
@@ -26,7 +25,6 @@ func BadRequest(err error, msg string) Error {
2625
// NotFound shortcut to return http.StatusNotFound with custom error and msg
2726
func NotFound(err error, msg string) Error {
2827
if err == nil {
29-
//nolint:goerr113
3028
err = errors.New("")
3129
}
3230
finalMsg := map[string][]string{"__error__": {msg}}
@@ -43,7 +41,6 @@ func NotFound(err error, msg string) Error {
4341
// NotFound shortcut to return http.StatusNotFound with custom error and msg
4442
func InternalError(err error, msg string) Error {
4543
if err == nil {
46-
//nolint:goerr113
4744
err = errors.New("")
4845
}
4946
finalMsg := map[string][]string{"__error__": {msg}}

server/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ func InitHandlerGroups(srv *HTTPServer, rg route.ConfiguratorIn) {
1010
srv.InitRoutes(group)
1111
}
1212
}
13-
1413
func NewHandlerGroups(groups ...any) fx.Option {
14+
//nolint:prealloc
1515
var annotates []any
1616

1717
for _, group := range groups {

server/http.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ import (
1111
"github.com/webdevelop-pro/go-common/configurator"
1212
"github.com/webdevelop-pro/go-common/context/keys"
1313
"github.com/webdevelop-pro/go-common/logger"
14-
"github.com/webdevelop-pro/go-common/validator"
15-
"go.uber.org/fx"
16-
1714
"github.com/webdevelop-pro/go-common/server/healthcheck"
1815
"github.com/webdevelop-pro/go-common/server/middleware"
1916
"github.com/webdevelop-pro/go-common/server/route"
17+
"github.com/webdevelop-pro/go-common/validator"
18+
"go.uber.org/fx"
2019
)
2120

2221
const component = "http_server"
@@ -27,6 +26,7 @@ type HTTPServer struct {
2726
config *Config
2827
}
2928

29+
3030
func InitAndRun() fx.Option {
3131
return fx.Module(component,
3232
// Init http server
@@ -41,6 +41,7 @@ func InitAndRun() fx.Option {
4141
),
4242
)
4343
}
44+
4445
func (s *HTTPServer) InitRoutes(rg route.Configurator) {
4546
for _, r := range rg.GetRoutes() {
4647
//nolint:gosec,scopelint

server/middleware/ip_address.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ func SetIPAddress(next echo.HandlerFunc) echo.HandlerFunc {
1212
ip := keys.GetIPAddress(c.Request().Header)
1313
c.Set(keys.IPAddressStr, ip)
1414

15+
//nolint:golint
1516
ctx := context.WithValue(c.Request().Context(), keys.IPAddressStr, ip)
1617
c.SetRequest(c.Request().WithContext(ctx))
1718
return next(c)

0 commit comments

Comments
 (0)