Skip to content

Commit 89fe739

Browse files
committed
bump golanglint-ci.
1 parent a51abbd commit 89fe739

11 files changed

Lines changed: 97 additions & 63 deletions

File tree

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Check out source
1919
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 #v3.5.3
2020
- name: Install Linters
21-
run: "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.53.3"
21+
run: "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.2.2"
2222
- name: Build
2323
run: go build ./...
2424
- name: Test

.golangci.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
version: 2
2+
13
run:
2-
deadline: 10m
4+
timeout: 10m
35

46
linters:
5-
disable-all: true
7+
default: none
68
enable:
9+
- staticcheck
710
- asciicheck
811
- bidichk
912
- bodyclose
10-
- gofmt
11-
- goimports
12-
- gosimple
1313
- govet
1414
- grouper
1515
- ineffassign
@@ -20,6 +20,10 @@ linters:
2020
- rowserrcheck
2121
- sqlclosecheck
2222
- tparallel
23-
- typecheck
2423
- unconvert
2524
- unused
25+
26+
formatters:
27+
enable:
28+
- gofmt
29+
- goimports

cmd/dcrtime/dcrtime.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func downloadV1(questions []string) error {
231231
for _, digest := range v.CollectionInformation.Digests {
232232
d, ok := convertDigest(digest)
233233
if !ok {
234-
return fmt.Errorf("Invalid digest "+
234+
return fmt.Errorf("invalid digest "+
235235
"server response for "+
236236
"timestamp: %v",
237237
v.ServerTimestamp)
@@ -469,7 +469,7 @@ func verifyTimestamps(vt []v2.VerifyTimestamp) error {
469469
for _, digest := range t.CollectionInformation.Digests {
470470
d, ok := convertDigest(digest)
471471
if !ok {
472-
return fmt.Errorf("Invalid digest "+
472+
return fmt.Errorf("invalid digest "+
473473
"server response for "+
474474
"timestamp: %v",
475475
t.ServerTimestamp)
@@ -568,7 +568,7 @@ func uploadV1(digests []string, exists map[string]string) error {
568568
var tsReply v1.TimestampReply
569569
decoder := json.NewDecoder(r.Body)
570570
if err := decoder.Decode(&tsReply); err != nil {
571-
return fmt.Errorf("Could node decode TimestampReply: %v", err)
571+
return fmt.Errorf("cloud not decode TimestampReply: %v", err)
572572
}
573573

574574
// Print human readable results.
@@ -638,7 +638,7 @@ func uploadV2Batch(digests []string, exists map[string]string) error {
638638
var tsReply v2.TimestampBatchReply
639639
decoder := json.NewDecoder(r.Body)
640640
if err := decoder.Decode(&tsReply); err != nil {
641-
return fmt.Errorf("Could node decode TimestampReply: %v", err)
641+
return fmt.Errorf("cloud not decode TimestampReply: %v", err)
642642
}
643643

644644
// Print human readable results.
@@ -704,7 +704,7 @@ func uploadV2Single(digest string, exists map[string]string) error {
704704
var tsReply v2.TimestampReply
705705
decoder := json.NewDecoder(r.Body)
706706
if err := decoder.Decode(&tsReply); err != nil {
707-
return fmt.Errorf("Could node decode TimestampReply: %v", err)
707+
return fmt.Errorf("cloud not decode TimestampReply: %v", err)
708708
}
709709

710710
// Print human readable results.
@@ -770,18 +770,18 @@ func showWalletBalanceV1() error {
770770
if response.StatusCode != http.StatusOK {
771771
e, err := getError(response.Body)
772772
if err != nil {
773-
return fmt.Errorf("Retrieve wallet balance failed: %v",
773+
return fmt.Errorf("retrieve wallet balance failed: %v",
774774
response.Status)
775775
}
776-
return fmt.Errorf("Retrieve wallet balance failed - %v: %v",
776+
return fmt.Errorf("retrieve wallet balance failed - %v: %v",
777777
response.Status, e)
778778
}
779779

780780
// Decode the response from dcrtimed
781781
var balance v1.WalletBalanceReply
782782
jsonDecoder := json.NewDecoder(response.Body)
783783
if err := jsonDecoder.Decode(&balance); err != nil {
784-
return fmt.Errorf("Could not decode WalletBalanceReply: %v", err)
784+
return fmt.Errorf("could not decode WalletBalanceReply: %v", err)
785785
}
786786

787787
if *verbose {
@@ -832,18 +832,18 @@ func showWalletBalanceV2() error {
832832
if response.StatusCode != http.StatusOK {
833833
e, err := getError(response.Body)
834834
if err != nil {
835-
return fmt.Errorf("Retrieve wallet balance failed: %v",
835+
return fmt.Errorf("retrieve wallet balance failed: %v",
836836
response.Status)
837837
}
838-
return fmt.Errorf("Retrieve wallet balance failed - %v: %v",
838+
return fmt.Errorf("retrieve wallet balance failed - %v: %v",
839839
response.Status, e)
840840
}
841841

842842
// Decode the response from dcrtimed
843843
var balance v2.WalletBalanceReply
844844
jsonDecoder := json.NewDecoder(response.Body)
845845
if err := jsonDecoder.Decode(&balance); err != nil {
846-
return fmt.Errorf("Could not decode WalletBalanceReply: %v", err)
846+
return fmt.Errorf("could not decode WalletBalanceReply: %v", err)
847847
}
848848

849849
if *verbose {
@@ -891,18 +891,18 @@ func lastAnchorV1() error {
891891
if response.StatusCode != http.StatusOK {
892892
e, err := getError(response.Body)
893893
if err != nil {
894-
return fmt.Errorf("Retrieve last anchor info failed: %v",
894+
return fmt.Errorf("retrieve last anchor info failed: %v",
895895
response.Status)
896896
}
897-
return fmt.Errorf("Retrieve last anchor info failed - %v: %v",
897+
return fmt.Errorf("retrieve last anchor info failed - %v: %v",
898898
response.Status, e)
899899
}
900900

901901
// Decode the response from dcrtimed
902902
var anchor v1.LastAnchorReply
903903
jsonDecoder := json.NewDecoder(response.Body)
904904
if err := jsonDecoder.Decode(&anchor); err != nil {
905-
return fmt.Errorf("Could not decode LastAnchorReply: %v", err)
905+
return fmt.Errorf("could not decode LastAnchorReply: %v", err)
906906
}
907907

908908
fmt.Printf(
@@ -946,18 +946,18 @@ func lastAnchorV2() error {
946946
if response.StatusCode != http.StatusOK {
947947
e, err := getError(response.Body)
948948
if err != nil {
949-
return fmt.Errorf("Retrieve last anchor info failed: %v",
949+
return fmt.Errorf("retrieve last anchor info failed: %v",
950950
response.Status)
951951
}
952-
return fmt.Errorf("Retrieve last anchor info failed - %v: %v",
952+
return fmt.Errorf("retrieve last anchor info failed - %v: %v",
953953
response.Status, e)
954954
}
955955

956956
// Decode the response from dcrtimed
957957
var anchor v2.LastAnchorReply
958958
jsonDecoder := json.NewDecoder(response.Body)
959959
if err := jsonDecoder.Decode(&anchor); err != nil {
960-
return fmt.Errorf("Could not decode LastAnchorReply: %v", err)
960+
return fmt.Errorf("could not decode LastAnchorReply: %v", err)
961961
}
962962

963963
fmt.Printf(
@@ -1018,18 +1018,18 @@ func lastDigestsV2(n int32) error {
10181018
if r.StatusCode != http.StatusOK {
10191019
e, err := getError(r.Body)
10201020
if err != nil {
1021-
return fmt.Errorf("Retrieve last %d digests info failed: %v", n,
1021+
return fmt.Errorf("retrieve last %d digests info failed: %v", n,
10221022
r.Status)
10231023
}
1024-
return fmt.Errorf("Retrieve last %d digests info failed - %v: %v",
1024+
return fmt.Errorf("retrieve last %d digests info failed - %v: %v",
10251025
n, r.Status, e)
10261026
}
10271027

10281028
// Decode the r from dcrtimed
10291029
var ldr v2.LastDigestsReply
10301030
jsonDecoder := json.NewDecoder(r.Body)
10311031
if err := jsonDecoder.Decode(&ldr); err != nil {
1032-
return fmt.Errorf("Could not decode LastDigestsReply: %v", err)
1032+
return fmt.Errorf("could not decode LastDigestsReply: %v", err)
10331033
}
10341034

10351035
fmt.Printf(
@@ -1074,7 +1074,7 @@ func loadCredentialsIfRequired() error {
10741074
// Token not provided via command line. Try to load via config file.
10751075
config, err := loadConfig()
10761076
if err != nil {
1077-
return fmt.Errorf("Attempt to load api token "+
1077+
return fmt.Errorf("attempt to load api token "+
10781078
"from configuration file failed: %v", err)
10791079
}
10801080

@@ -1134,7 +1134,7 @@ func _main() error {
11341134
lastAnchorInfo = lastAnchorV2
11351135
lastDigestsInfo = lastDigestsV2
11361136
default:
1137-
return fmt.Errorf("Invalid API version %v", *apiVersion)
1137+
return fmt.Errorf("invalid API version %v", *apiVersion)
11381138
}
11391139

11401140
if *host == "" {

cmd/dcrtime_checker/dcrtime_checker.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func verifyV2(digest string, fProof *os.File) error {
2929
var vr v2.VerifyBatchReply
3030
decoder := json.NewDecoder(fProof)
3131
if err := decoder.Decode(&vr); err != nil {
32-
return fmt.Errorf("Could node decode VerifyBatchReply: %v", err)
32+
return fmt.Errorf("could not decode VerifyBatchReply: %v", err)
3333
}
3434

3535
// Ensure file digest exists in the proof and that the saved answer was
@@ -97,7 +97,7 @@ func verifyV1(digest string, fProof *os.File) error {
9797
var vr v1.VerifyReply
9898
decoder := json.NewDecoder(fProof)
9999
if err := decoder.Decode(&vr); err != nil {
100-
return fmt.Errorf("Could node decode VerifyReply: %v", err)
100+
return fmt.Errorf("could not decode VerifyReply: %v", err)
101101
}
102102

103103
// Ensure file digest exists in the proof and that the saved answer was
@@ -178,7 +178,7 @@ func _main() error {
178178
case v2.APIVersion:
179179
verify = verifyV2
180180
default:
181-
return fmt.Errorf("Invalid API version %v", *apiVersion)
181+
return fmt.Errorf("invalid API version %v", *apiVersion)
182182
}
183183

184184
// require -f

dcrtimed/backend/filesystem/filesystem.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -463,14 +463,17 @@ func (fs *FileSystem) getTimestamp(timestamp int64) (backend.TimestampResult, er
463463
if fr.ChainTimestamp == 0 && !fs.testing {
464464
lfr, err := fs.lazyFlush(timestamp, fr)
465465
if err != nil {
466-
if err == errNotEnoughConfirmation {
466+
switch err {
467+
case errNotEnoughConfirmation:
467468
gtme.Confirmations = &lfr.Confirmations
468469
gtme.MinConfirmations = fs.confirmations
469-
} else if err == errInvalidConfirmations {
470+
471+
case errInvalidConfirmations:
470472
log.Errorf("%v: Confirmations = -1",
471473
fr.Tx.String())
472474
return gtme, err
473-
} else {
475+
476+
default:
474477
return gtme, err
475478
}
476479
}
@@ -549,23 +552,29 @@ func (fs *FileSystem) getDigest(now time.Time, current *leveldb.DB, digest [sha2
549552
gdme.Timestamp = fr.ServerTimestamp
550553
gdme.FlushTimestamp = fr.FlushTimestamp
551554

555+
switch {
552556
// Override error code during testing
553-
if fs.testing {
557+
case fs.testing:
554558
gdme.ErrorCode = foundGlobal
555-
} else if gdme.AnchoredTimestamp == 0 {
559+
560+
case gdme.AnchoredTimestamp == 0:
556561
lfr, err := fs.lazyFlush(dbts, fr)
557562
if err != nil {
558-
if err == errNotEnoughConfirmation {
563+
switch err {
564+
case errNotEnoughConfirmation:
559565
gdme.Confirmations = &lfr.Confirmations
560566
gdme.MinConfirmations = fs.confirmations
561-
} else if err == errInvalidConfirmations {
567+
568+
case errInvalidConfirmations:
562569
log.Errorf("%v: Confirmations = -1",
563570
fr.Tx.String())
564571
return gdme, err
565-
} else {
572+
573+
default:
566574
return gdme, err
567575
}
568576
}
577+
569578
gdme.AnchoredTimestamp = fr.ChainTimestamp
570579
}
571580

@@ -755,7 +764,7 @@ func (fs *FileSystem) GetTimestamps(timestamps []int64) ([]backend.TimestampResu
755764
// Get the last n digests in the added to the Backend
756765
func (fs *FileSystem) LastDigests(n int32) ([]backend.GetResult, error) {
757766
if n > fs.maxDigests {
758-
return nil, fmt.Errorf("Invalid number %d of digests requested. Max is: %d", n, fs.maxDigests)
767+
return nil, fmt.Errorf("invalid number %d of digests requested. Max is: %d", n, fs.maxDigests)
759768
}
760769

761770
results := make([]backend.GetResult, 0)
@@ -776,7 +785,7 @@ func (fs *FileSystem) LastDigests(n int32) ([]backend.GetResult, error) {
776785
break
777786
}
778787
if !files[i].IsDir() {
779-
return nil, fmt.Errorf("Unexpected file %v",
788+
return nil, fmt.Errorf("unexpected file %v",
780789
filepath.Join(fs.root, files[i].Name()))
781790
}
782791

dcrtimed/backend/filesystem/fsck.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ func (fs *FileSystem) fsckTimestamps(options *backend.FsckOptions, empties map[i
376376

377377
for _, fi := range files {
378378
if !fi.IsDir() {
379-
return fmt.Errorf("Unexpected file %v",
379+
return fmt.Errorf("unexpected file %v",
380380
filepath.Join(fs.root, fi.Name()))
381381
}
382382
if fi.Name() == globalDBDir {
@@ -453,9 +453,8 @@ func (fs *FileSystem) fsckGlobal(options *backend.FsckOptions, empties map[int64
453453
// At this point we treat this as fatal because there
454454
// is no need to write code for theoretical issues that
455455
// should not have happned.
456-
return fmt.Errorf(" *** ERROR hash not found in "+
457-
"timestamp : %v %v\n", filepath.Join(fs.root,
458-
ts2dirname(value)), key)
456+
return fmt.Errorf("hash not found in timestamp : %v %v", filepath.Join(
457+
fs.root, ts2dirname(value)), key)
459458
}
460459

461460
// Check to see if this timestamp exists in the empties map.
@@ -618,7 +617,7 @@ func (fs *FileSystem) fsckDups(options *backend.FsckOptions) error {
618617
digests := make(map[string]int64)
619618
for _, fi := range files {
620619
if !fi.IsDir() {
621-
return fmt.Errorf("Unexpected file %v",
620+
return fmt.Errorf("unexpected file %v",
622621
filepath.Join(fs.root, fi.Name()))
623622
}
624623
if fi.Name() == globalDBDir {

dcrtimed/config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func parseAndSetDebugLevels(debugLevel string) error {
136136
if !strings.Contains(debugLevel, ",") && !strings.Contains(debugLevel, "=") {
137137
// Validate debug log level.
138138
if !validLogLevel(debugLevel) {
139-
str := "The specified debug level [%v] is invalid"
139+
str := "the specified debug level [%v] is invalid"
140140
return fmt.Errorf(str, debugLevel)
141141
}
142142

@@ -150,7 +150,7 @@ func parseAndSetDebugLevels(debugLevel string) error {
150150
// issues and update the log levels accordingly.
151151
for _, logLevelPair := range strings.Split(debugLevel, ",") {
152152
if !strings.Contains(logLevelPair, "=") {
153-
str := "The specified debug level contains an invalid " +
153+
str := "the specified debug level contains an invalid " +
154154
"subsystem/level pair [%v]"
155155
return fmt.Errorf(str, logLevelPair)
156156
}
@@ -161,14 +161,14 @@ func parseAndSetDebugLevels(debugLevel string) error {
161161

162162
// Validate subsystem.
163163
if _, exists := subsystemLoggers[subsysID]; !exists {
164-
str := "The specified subsystem [%v] is invalid -- " +
164+
str := "the specified subsystem [%v] is invalid -- " +
165165
"supported subsytems %v"
166166
return fmt.Errorf(str, subsysID, supportedSubsystems())
167167
}
168168

169169
// Validate log level.
170170
if !validLogLevel(logLevel) {
171-
str := "The specified debug level [%v] is invalid"
171+
str := "the specified debug level [%v] is invalid"
172172
return fmt.Errorf(str, logLevel)
173173
}
174174

@@ -239,7 +239,7 @@ func parseAndValidateAPIVersions(vs string) ([]uint, error) {
239239

240240
// Validate out of bounds config
241241
if len(versions) == 0 || len(versions) > 2 {
242-
return nil, fmt.Errorf("Invalid API versions config," +
242+
return nil, fmt.Errorf("invalid API versions config," +
243243
"must have at least one and at most two")
244244
}
245245

0 commit comments

Comments
 (0)