Skip to content

Commit aea0cc9

Browse files
Fix: linter
1 parent 4d8eab9 commit aea0cc9

File tree

20 files changed

+153
-110
lines changed

20 files changed

+153
-110
lines changed

.golangci.yml

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,43 @@
1+
version: "2"
12
linters:
23
enable:
4+
- containedctx
5+
- copyloopvar
36
- goconst
47
- gocritic
5-
- gofmt
6-
- govet
8+
- gosec
9+
- makezero
10+
- mirror
11+
- misspell
12+
- musttag
13+
- noctx
714
- prealloc
15+
- protogetter
16+
- tagalign
817
- unconvert
9-
- errcheck
10-
- ineffassign
11-
- typecheck
12-
- containedctx
1318
- usetesting
14-
- unused
19+
- zerologlint
20+
settings:
21+
gosec:
22+
excludes:
23+
- G115
24+
exclusions:
25+
generated: lax
26+
presets:
27+
- comments
28+
- common-false-positives
29+
- legacy
30+
- std-error-handling
31+
paths:
32+
- third_party$
33+
- builtin$
34+
- examples$
35+
formatters:
36+
enable:
37+
- gofmt
38+
exclusions:
39+
generated: lax
40+
paths:
41+
- third_party$
42+
- builtin$
43+
- examples$

config/config.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import (
1111

1212
// Config
1313
type Config struct {
14-
Version string `yaml:"version" validate:"required"`
15-
Database Database `yaml:"database" validate:"required"`
14+
Version string `validate:"required" yaml:"version"`
15+
Database Database `validate:"required" yaml:"database"`
1616
DataSources map[string]DataSource `yaml:"datasources,omitempty"`
1717
Contracts map[string]Contract `yaml:"contracts,omitempty"`
18-
Hasura *Hasura `yaml:"hasura,omitempty" validate:"omitempty"`
19-
Prometheus *Prometheus `yaml:"prometheus,omitempty" validate:"omitempty"`
18+
Hasura *Hasura `validate:"omitempty" yaml:"hasura,omitempty"`
19+
Prometheus *Prometheus `validate:"omitempty" yaml:"prometheus,omitempty"`
2020
}
2121

2222
// Substitute -
@@ -27,27 +27,27 @@ func (c *Config) Substitute() error {
2727
// DataSource -
2828
type DataSource struct {
2929
Kind string `yaml:"kind"`
30-
URL string `yaml:"url" validate:"required,url"`
31-
Credentials *Credentials `yaml:"credentials,omitempty" validate:"omitempty"`
32-
Timeout uint `yaml:"timeout" validate:"omitempty"`
33-
RequestsPerSecond int `yaml:"rps" validate:"omitempty,min=1"`
30+
URL string `validate:"required,url" yaml:"url"`
31+
Credentials *Credentials `validate:"omitempty" yaml:"credentials,omitempty"`
32+
Timeout uint `validate:"omitempty" yaml:"timeout"`
33+
RequestsPerSecond int `validate:"omitempty,min=1" yaml:"rps"`
3434
}
3535

3636
// Contracts -
3737
type Contract struct {
38-
Address string `yaml:"address" validate:"required,len=36"`
38+
Address string `validate:"required,len=36" yaml:"address"`
3939
TypeName string `yaml:"typename"`
4040
}
4141

4242
// Database
4343
type Database struct {
4444
Path string `yaml:"path,omitempty"`
45-
Kind string `yaml:"kind" validate:"required,oneof=sqlite postgres mysql clickhouse elasticsearch"`
46-
Host string `yaml:"host" validate:"required_with=Port User Database"`
47-
Port int `yaml:"port" validate:"required_with=Host User Database,gt=-1,lt=65535"`
48-
User string `yaml:"user" validate:"required_with=Host Port Database"`
45+
Kind string `validate:"required,oneof=sqlite postgres mysql clickhouse elasticsearch" yaml:"kind"`
46+
Host string `validate:"required_with=Port User Database" yaml:"host"`
47+
Port int `validate:"required_with=Host User Database,gt=-1,lt=65535" yaml:"port"`
48+
User string `validate:"required_with=Host Port Database" yaml:"user"`
4949
Password string `yaml:"password"`
50-
Database string `yaml:"database" validate:"required_with=Host Port User"`
50+
Database string `validate:"required_with=Host Port User" yaml:"database"`
5151
SchemaName string `yaml:"schema_name"`
5252
ApplicationName string `yaml:"application_name"`
5353
MaxOpenConnections int `yaml:"max_open_connections"`
@@ -57,17 +57,17 @@ type Database struct {
5757

5858
// Hasura -
5959
type Hasura struct {
60-
URL string `yaml:"url" validate:"required,url"`
61-
Secret string `yaml:"admin_secret" validate:"required"`
62-
RowsLimit uint64 `yaml:"select_limit" validate:"gt=0"`
60+
URL string `validate:"required,url" yaml:"url"`
61+
Secret string `validate:"required" yaml:"admin_secret"`
62+
RowsLimit uint64 `validate:"gt=0" yaml:"select_limit"`
6363
EnableAggregations bool `yaml:"allow_aggregation"`
6464
Source *HasuraSource `yaml:"source"`
6565
Rest *bool `yaml:"rest"`
6666
UnauthorizedRole string `yaml:"unauthorized_role"`
6767
}
6868

6969
type HasuraSource struct {
70-
Name string `yaml:"name" validate:"required"`
70+
Name string `validate:"required" yaml:"name"`
7171
DatabaseHost string `yaml:"database_host"`
7272
UsePreparedStatements bool `yaml:"use_prepared_statements"`
7373
IsolationLevel string `yaml:"isolation_level"`
@@ -89,7 +89,7 @@ func (h *Hasura) UnmarshalYAML(unmarshal func(interface{}) error) error {
8989

9090
// Prometheus -
9191
type Prometheus struct {
92-
URL string `yaml:"url" validate:"required"`
92+
URL string `validate:"required" yaml:"url"`
9393
}
9494

9595
// Load - load default config from `filename`

config/credentials.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ package config
22

33
// Credentials -
44
type Credentials struct {
5-
User *UserCredentials `yaml:"user,omitempty" validate:"omitempty"`
6-
ApiKey *ApiKey `yaml:"api_key,omitempty" validate:"omitempty"`
5+
User *UserCredentials `validate:"omitempty" yaml:"user,omitempty"`
6+
ApiKey *ApiKey `validate:"omitempty" yaml:"api_key,omitempty"`
77
}
88

99
// UserCredentials -
1010
type UserCredentials struct {
11-
Name string `yaml:"name" validate:"required"`
12-
Password string `yaml:"password" validate:"required"`
11+
Name string `validate:"required" yaml:"name"`
12+
Password string `validate:"required" yaml:"password"`
1313
}
1414

1515
type ApiKey struct {
16-
Header string `yaml:"header" validate:"required"`
17-
Key string `yaml:"key" validate:"required"`
16+
Header string `validate:"required" yaml:"header"`
17+
Key string `validate:"required" yaml:"key"`
1818
}

config/parsing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (t *expandTransformer) Transform(dst, src []byte, atEOF bool) (int, int, er
6868
def = `""`
6969
}
7070

71-
if _, err := buf.Write([]byte(def)); err != nil {
71+
if _, err := buf.WriteString(def); err != nil {
7272
return 0, 0, err
7373
}
7474

database/comment_test.go

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func initMocks(t *testing.T) (*gomock.Controller, *mocks.MockSchemeCommenter) {
1919
func TestMakeCommentsWithTableName(t *testing.T) {
2020
type Ballot struct {
2121
//nolint
22-
tableName struct{} `pg:"ballots" comment:"Ballot table"`
22+
tableName struct{} `comment:"Ballot table" pg:"ballots"`
2323
Ballot string `json:"ballot"`
2424
}
2525

@@ -76,7 +76,7 @@ func TestMakeCommentsFieldWithPgComment(t *testing.T) {
7676
type Ballot struct {
7777
//nolint
7878
tableName struct{} `pg:"ballots"`
79-
Ballot string `json:"ballot" comment:"This is field comment"`
79+
Ballot string `comment:"This is field comment" json:"ballot"`
8080
}
8181

8282
mockCtrl, mockSC := initMocks(t)
@@ -101,22 +101,22 @@ func TestMakeCommentsFieldWithPgComment(t *testing.T) {
101101
func TestMakeCommentsWithTableNameAndFieldsWithPgComment(t *testing.T) {
102102
type Ballot struct {
103103
//nolint
104-
tableName struct{} `pg:"ballots" comment:"Ballot table"`
105-
CreatedAt int64 `json:"-" comment:"This is field comment"`
106-
UpdatedAt int64 `json:"-" comment:"This is field comment"`
107-
Network string `json:"network" pg:",pk" comment:"This is field comment"`
108-
Hash string `json:"hash" pg:",pk" comment:"This is field comment"`
109-
Branch string `json:"branch" comment:"This is field comment"`
110-
Status string `json:"status" comment:"This is field comment"`
111-
Kind string `json:"kind" comment:"This is field comment"`
112-
Signature string `json:"signature" comment:"This is field comment"`
113-
Protocol string `json:"protocol" comment:"This is field comment"`
114-
Level uint64 `json:"level" comment:"This is field comment"`
115-
Errors interface{} `json:"errors,omitempty" pg:"type:jsonb" comment:"This is field comment"`
116-
ExpirationLevel *uint64 `json:"expiration_level" comment:"This is field comment"`
117-
Raw interface{} `json:"raw,omitempty" pg:"type:jsonb" comment:"This is field comment"`
118-
Ballot string `json:"ballot" comment:"This is field comment"`
119-
Period int64 `json:"period" comment:"This is field comment"`
104+
tableName struct{} `comment:"Ballot table" pg:"ballots"`
105+
CreatedAt int64 `comment:"This is field comment" json:"-"`
106+
UpdatedAt int64 `comment:"This is field comment" json:"-"`
107+
Network string `comment:"This is field comment" json:"network" pg:",pk"`
108+
Hash string `comment:"This is field comment" json:"hash" pg:",pk"`
109+
Branch string `comment:"This is field comment" json:"branch"`
110+
Status string `comment:"This is field comment" json:"status"`
111+
Kind string `comment:"This is field comment" json:"kind"`
112+
Signature string `comment:"This is field comment" json:"signature"`
113+
Protocol string `comment:"This is field comment" json:"protocol"`
114+
Level uint64 `comment:"This is field comment" json:"level"`
115+
Errors interface{} `comment:"This is field comment" json:"errors,omitempty" pg:"type:jsonb"`
116+
ExpirationLevel *uint64 `comment:"This is field comment" json:"expiration_level"`
117+
Raw interface{} `comment:"This is field comment" json:"raw,omitempty" pg:"type:jsonb"`
118+
Ballot string `comment:"This is field comment" json:"ballot"`
119+
Period int64 `comment:"This is field comment" json:"period"`
120120
}
121121

122122
mockCtrl, mockSC := initMocks(t)
@@ -148,8 +148,8 @@ func TestMakeCommentsWithTableNameAndFieldsWithPgComment(t *testing.T) {
148148
func TestMakeCommentsWithMultipleModels(t *testing.T) {
149149
type Ballot struct {
150150
//nolint
151-
tableName struct{} `pg:"ballots" comment:"This multiple table name comment"`
152-
Ballot string `json:"ballot" comment:"This is multiple field comment"`
151+
tableName struct{} `comment:"This multiple table name comment" pg:"ballots"`
152+
Ballot string `comment:"This is multiple field comment" json:"ballot"`
153153
}
154154

155155
mockCtrl, mockSC := initMocks(t)
@@ -182,8 +182,8 @@ func TestMakeCommentsWithMultipleModels(t *testing.T) {
182182
func TestMakeCommentsWithMultipleModelsByPointers(t *testing.T) {
183183
type Ballot struct {
184184
//nolint
185-
tableName struct{} `pg:"ballots" comment:"This multiple table name comment"`
186-
Ballot string `json:"ballot" comment:"This is multiple field comment"`
185+
tableName struct{} `comment:"This multiple table name comment" pg:"ballots"`
186+
Ballot string `comment:"This is multiple field comment" json:"ballot"`
187187
}
188188

189189
mockCtrl, mockSC := initMocks(t)
@@ -217,7 +217,7 @@ func TestMakeCommentsIgnoreFieldWithPgHyphen(t *testing.T) {
217217
type Ballot struct {
218218
//nolint
219219
tableName struct{} `pg:"ballots"`
220-
Ballot string `json:"ballot" pg:"-" comment:"This is field comment"`
220+
Ballot string `comment:"This is field comment" json:"ballot" pg:"-"`
221221
}
222222

223223
mockCtrl, mockSC := initMocks(t)
@@ -242,7 +242,7 @@ func TestMakeCommentsIgnoreFieldsWithEmptyComment(t *testing.T) {
242242
type Ballot struct {
243243
//nolint
244244
tableName struct{} `pg:"ballots"`
245-
Ballot string `json:"ballot" comment:""`
245+
Ballot string `comment:"" json:"ballot"`
246246
}
247247

248248
mockCtrl, mockSC := initMocks(t)
@@ -299,16 +299,16 @@ func TestMakeCommentsIgnoreNoModels(t *testing.T) {
299299

300300
func TestMakeCommentsWithStructCompositionAndCorrectOrder(t *testing.T) {
301301
type Operation struct {
302-
CreatedAt int64 `json:"-" comment:"Date of creation in seconds since UNIX epoch."`
303-
UpdatedAt int64 `json:"-" comment:"Date of last update in seconds since UNIX epoch."`
304-
Network string `json:"network" pg:",pk" comment:"Identifies belonging network."`
302+
CreatedAt int64 `comment:"Date of creation in seconds since UNIX epoch." json:"-"`
303+
UpdatedAt int64 `comment:"Date of last update in seconds since UNIX epoch." json:"-"`
304+
Network string `comment:"Identifies belonging network." json:"network" pg:",pk"`
305305
}
306306

307307
type Ballot struct {
308308
//nolint
309-
tableName struct{} `pg:"ballots" comment:"This table name comment"`
309+
tableName struct{} `comment:"This table name comment" pg:"ballots"`
310310
Operation
311-
Ballot string `json:"ballot" comment:"This is field comment"`
311+
Ballot string `comment:"This is field comment" json:"ballot"`
312312
}
313313

314314
mockCtrl, mockSC := initMocks(t)
@@ -360,24 +360,24 @@ func TestMakeCommentsWithStructCompositionAndCorrectOrder(t *testing.T) {
360360

361361
func TestMakeCommentsWithDeepStructComposition(t *testing.T) {
362362
type CreatedMetadata struct {
363-
CreatedAt int64 `json:"-" comment:"Date of creation in seconds since UNIX epoch."`
363+
CreatedAt int64 `comment:"Date of creation in seconds since UNIX epoch." json:"-"`
364364
}
365365

366366
type UpdatedMetadata struct {
367367
CreatedMetadata
368-
UpdatedAt int64 `json:"-" comment:"Date of last update in seconds since UNIX epoch."`
368+
UpdatedAt int64 `comment:"Date of last update in seconds since UNIX epoch." json:"-"`
369369
}
370370

371371
type Operation struct {
372372
UpdatedMetadata
373-
Network string `json:"network" pg:",pk" comment:"Identifies belonging network."`
373+
Network string `comment:"Identifies belonging network." json:"network" pg:",pk"`
374374
}
375375

376376
type Ballot struct {
377377
//nolint
378-
tableName struct{} `pg:"ballots" comment:"This table name comment"`
378+
tableName struct{} `comment:"This table name comment" pg:"ballots"`
379379
Operation
380-
Ballot string `json:"ballot" comment:"This is field comment"`
380+
Ballot string `comment:"This is field comment" json:"ballot"`
381381
}
382382

383383
mockCtrl, mockSC := initMocks(t)
@@ -430,17 +430,17 @@ func TestMakeCommentsWithDeepStructComposition(t *testing.T) {
430430
func TestMakeCommentsWithStructCompositionErrorOnEmbeddedTableName(t *testing.T) {
431431
type Operation struct {
432432
//nolint
433-
tableName struct{} `pg:"operation" comment:"This embedded type tableName comment."`
434-
CreatedAt int64 `json:"-" comment:"Date of creation in seconds since UNIX epoch."`
435-
UpdatedAt int64 `json:"-" comment:"Date of last update in seconds since UNIX epoch."`
436-
Network string `json:"network" pg:",pk" comment:"Identifies belonging network."`
433+
tableName struct{} `comment:"This embedded type tableName comment." pg:"operation"`
434+
CreatedAt int64 `comment:"Date of creation in seconds since UNIX epoch." json:"-"`
435+
UpdatedAt int64 `comment:"Date of last update in seconds since UNIX epoch." json:"-"`
436+
Network string `comment:"Identifies belonging network." json:"network" pg:",pk"`
437437
}
438438

439439
type Ballot struct {
440440
//nolint
441-
tableName struct{} `pg:"ballots" comment:"This table name comment"`
441+
tableName struct{} `comment:"This table name comment" pg:"ballots"`
442442
Operation
443-
Ballot string `json:"ballot" comment:"This is field comment"`
443+
Ballot string `comment:"This is field comment" json:"ballot"`
444444
}
445445

446446
mockCtrl, mockSC := initMocks(t)
@@ -464,10 +464,10 @@ func TestMakeCommentsWithStructCompositionErrorOnEmbeddedTableName(t *testing.T)
464464

465465
func TestMakeCommentsWithBunBaseModel(t *testing.T) {
466466
type Operation struct {
467-
bun.BaseModel `pg:"-" bun:"table:operation" comment:"This is bun comment."`
468-
CreatedAt int64 `json:"-" comment:"Date of creation in seconds since UNIX epoch."`
469-
UpdatedAt int64 `json:"-" comment:"Date of last update in seconds since UNIX epoch."`
470-
Network string `json:"network" bun:",pk" comment:"Identifies belonging network."`
467+
bun.BaseModel `bun:"table:operation" comment:"This is bun comment." pg:"-"`
468+
CreatedAt int64 `comment:"Date of creation in seconds since UNIX epoch." json:"-"`
469+
UpdatedAt int64 `comment:"Date of last update in seconds since UNIX epoch." json:"-"`
470+
Network string `bun:",pk" comment:"Identifies belonging network." json:"network"`
471471
}
472472

473473
mockCtrl, mockSC := initMocks(t)

database/state.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ import (
1010
// State -
1111
type State struct {
1212
//nolint
13-
tableName struct{} `gorm:"-" bun:"-" pg:"dipdup_state" json:"-" comment:"Indexer state table"`
14-
bun.BaseModel `gorm:"-" pg:"-" bun:"dipdup_state" json:"-" comment:"Indexer state table"`
15-
16-
IndexName string `gorm:"primaryKey" pg:",pk" bun:",pk" json:"index_name" comment:"Index name"`
17-
IndexType string `json:"index_type" comment:"Index type"`
18-
Hash string `json:"hash" comment:"Current hash"`
19-
Timestamp time.Time `json:"timestamp" comment:"Current timestamp"`
20-
Level uint64 `json:"level" comment:"Index level"`
21-
UpdatedAt int `gorm:"autoUpdateTime" comment:"Last updated timestamp"`
22-
CreatedAt int `gorm:"autoCreateTime" comment:"Created timestamp"`
13+
tableName struct{} `bun:"-" comment:"Indexer state table" gorm:"-" json:"-" pg:"dipdup_state"`
14+
bun.BaseModel `bun:"dipdup_state" comment:"Indexer state table" gorm:"-" json:"-" pg:"-"`
15+
16+
IndexName string `bun:",pk" comment:"Index name" gorm:"primaryKey" json:"index_name" pg:",pk"`
17+
IndexType string `comment:"Index type" json:"index_type"`
18+
Hash string `comment:"Current hash" json:"hash"`
19+
Timestamp time.Time `comment:"Current timestamp" json:"timestamp"`
20+
Level uint64 `comment:"Index level" json:"level"`
21+
UpdatedAt int `comment:"Last updated timestamp" gorm:"autoUpdateTime"`
22+
CreatedAt int `comment:"Created timestamp" gorm:"autoCreateTime"`
2323
}
2424

2525
var _ bun.BeforeAppendModelHook = (*State)(nil)

0 commit comments

Comments
 (0)