Skip to content

Commit 4b422d9

Browse files
authored
Fix problems reported by linters (#266)
This PR fixes a few problems reported by `golangcgi-lint`. This PR contributes to #264.
2 parents 1d8ae4c + ff872bc commit 4b422d9

File tree

6 files changed

+119
-117
lines changed

6 files changed

+119
-117
lines changed

calendar/julian/julian.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (j Julian) ToGregorian() (g Gregorian) {
110110
month -= 13
111111
year -= 4715
112112
} else {
113-
month -= 1
113+
month--
114114
year -= 4716
115115
}
116116
f *= 24

calendar/lunar/lunar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ var (
5656
}
5757

5858
InvalidDateError = func() error {
59-
return fmt.Errorf("invalid invalid date, please make sure the date is valid")
59+
return fmt.Errorf("invalid date, please make sure the date is valid")
6060
}
6161
)
6262

database.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package carbon
33
import (
44
"bytes"
55
"database/sql/driver"
6-
"errors"
76
"fmt"
87
"strconv"
98
"time"
@@ -12,7 +11,7 @@ import (
1211
// returns a failed scan error.
1312
// 失败的扫描错误
1413
var failedScanError = func(src interface{}) error {
15-
return errors.New(fmt.Sprintf("failed to scan value: %v", src))
14+
return fmt.Errorf("failed to scan value: %v", src)
1615
}
1716

1817
// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable.
@@ -48,7 +47,7 @@ func (c Carbon) MarshalJSON() ([]byte, error) {
4847
// UnmarshalJSON implements the interface json.Unmarshal for Carbon struct.
4948
// 实现 json.Unmarshaler 接口
5049
func (c *Carbon) UnmarshalJSON(b []byte) error {
51-
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
50+
value := string(bytes.Trim(b, `"`))
5251
if value == "" || value == "null" {
5352
return nil
5453
}
@@ -89,7 +88,7 @@ func (t DateTime) MarshalJSON() ([]byte, error) {
8988
// UnmarshalJSON implements the interface json.Unmarshal for DateTime struct.
9089
// 实现 UnmarshalJSON 接口
9190
func (t *DateTime) UnmarshalJSON(b []byte) error {
92-
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
91+
value := string(bytes.Trim(b, `"`))
9392
if value == "" || value == "null" {
9493
return nil
9594
}
@@ -133,7 +132,7 @@ func (t DateTimeMilli) MarshalJSON() ([]byte, error) {
133132
// UnmarshalJSON implements the interface json.Unmarshal for DateTimeMilli struct.
134133
// 实现 UnmarshalJSON 接口
135134
func (t *DateTimeMilli) UnmarshalJSON(b []byte) error {
136-
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
135+
value := string(bytes.Trim(b, `"`))
137136
if value == "" || value == "null" {
138137
return nil
139138
}
@@ -177,7 +176,7 @@ func (t DateTimeMicro) MarshalJSON() ([]byte, error) {
177176
// UnmarshalJSON implements the interface json.Unmarshal for DateTimeMicro struct.
178177
// 实现 UnmarshalJSON 接口
179178
func (t *DateTimeMicro) UnmarshalJSON(b []byte) error {
180-
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
179+
value := string(bytes.Trim(b, `"`))
181180
if value == "" || value == "null" {
182181
return nil
183182
}
@@ -221,7 +220,7 @@ func (t DateTimeNano) MarshalJSON() ([]byte, error) {
221220
// UnmarshalJSON implements the interface json.Unmarshal for DateTimeNano struct.
222221
// 实现 UnmarshalJSON 接口
223222
func (t *DateTimeNano) UnmarshalJSON(b []byte) error {
224-
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
223+
value := string(bytes.Trim(b, `"`))
225224
if value == "" || value == "null" {
226225
return nil
227226
}
@@ -265,7 +264,7 @@ func (t Date) MarshalJSON() ([]byte, error) {
265264
// UnmarshalJSON implements the interface json.Unmarshal for Date struct.
266265
// 实现 UnmarshalJSON 接口
267266
func (t *Date) UnmarshalJSON(b []byte) error {
268-
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
267+
value := string(bytes.Trim(b, `"`))
269268
if value == "" || value == "null" {
270269
return nil
271270
}
@@ -309,7 +308,7 @@ func (t DateMilli) MarshalJSON() ([]byte, error) {
309308
// UnmarshalJSON implements the interface json.Unmarshal for DateMilli struct.
310309
// 实现 UnmarshalJSON 接口
311310
func (t *DateMilli) UnmarshalJSON(b []byte) error {
312-
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
311+
value := string(bytes.Trim(b, `"`))
313312
if value == "" || value == "null" {
314313
return nil
315314
}
@@ -353,7 +352,7 @@ func (t DateMicro) MarshalJSON() ([]byte, error) {
353352
// UnmarshalJSON implements the interface json.Unmarshal for DateMicro struct.
354353
// 实现 UnmarshalJSON 接口
355354
func (t *DateMicro) UnmarshalJSON(b []byte) error {
356-
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
355+
value := string(bytes.Trim(b, `"`))
357356
if value == "" || value == "null" {
358357
return nil
359358
}
@@ -397,7 +396,7 @@ func (t DateNano) MarshalJSON() ([]byte, error) {
397396
// UnmarshalJSON implements the interface json.Unmarshal for DateNano struct.
398397
// 实现 UnmarshalJSON 接口
399398
func (t *DateNano) UnmarshalJSON(b []byte) error {
400-
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
399+
value := string(bytes.Trim(b, `"`))
401400
if value == "" || value == "null" {
402401
return nil
403402
}
@@ -441,7 +440,7 @@ func (t Time) MarshalJSON() ([]byte, error) {
441440
// UnmarshalJSON implements the interface json.Unmarshal for Time struct.
442441
// 实现 UnmarshalJSON 接口
443442
func (t *Time) UnmarshalJSON(b []byte) error {
444-
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
443+
value := string(bytes.Trim(b, `"`))
445444
if value == "" || value == "null" {
446445
return nil
447446
}
@@ -487,7 +486,7 @@ func (t TimeMilli) MarshalJSON() ([]byte, error) {
487486
// UnmarshalJSON implements the interface json.Unmarshal for TimeMilli struct.
488487
// 实现 UnmarshalJSON 接口
489488
func (t *TimeMilli) UnmarshalJSON(b []byte) error {
490-
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
489+
value := string(bytes.Trim(b, `"`))
491490
if value == "" || value == "null" {
492491
return nil
493492
}
@@ -532,7 +531,7 @@ func (t TimeMicro) MarshalJSON() ([]byte, error) {
532531
// UnmarshalJSON implements the interface json.Unmarshal for TimeMicro struct.
533532
// 实现 UnmarshalJSON 接口
534533
func (t *TimeMicro) UnmarshalJSON(b []byte) error {
535-
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
534+
value := string(bytes.Trim(b, `"`))
536535
if value == "" || value == "null" {
537536
return nil
538537
}
@@ -577,7 +576,7 @@ func (t TimeNano) MarshalJSON() ([]byte, error) {
577576
// UnmarshalJSON implements the interface json.Unmarshal for TimeNano struct.
578577
// 实现 UnmarshalJSON 接口
579578
func (t *TimeNano) UnmarshalJSON(b []byte) error {
580-
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
579+
value := string(bytes.Trim(b, `"`))
581580
if value == "" || value == "null" {
582581
return nil
583582
}
@@ -622,7 +621,7 @@ func (t Timestamp) MarshalJSON() ([]byte, error) {
622621
// UnmarshalJSON implements the interface json.Unmarshal for Timestamp struct.
623622
// 实现 UnmarshalJSON 接口
624623
func (t *Timestamp) UnmarshalJSON(b []byte) error {
625-
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
624+
value := string(bytes.Trim(b, `"`))
626625
if value == "" || value == "null" {
627626
return nil
628627
}
@@ -667,7 +666,7 @@ func (t TimestampMilli) MarshalJSON() ([]byte, error) {
667666
// UnmarshalJSON implements the interface json.Unmarshal for TimestampMilli struct.
668667
// 实现 UnmarshalJSON 接口
669668
func (t *TimestampMilli) UnmarshalJSON(b []byte) error {
670-
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
669+
value := string(bytes.Trim(b, `"`))
671670
if value == "" || value == "null" {
672671
return nil
673672
}
@@ -712,7 +711,7 @@ func (t TimestampMicro) MarshalJSON() ([]byte, error) {
712711
// UnmarshalJSON implements the interface json.Unmarshal for TimestampMicro struct.
713712
// 实现 UnmarshalJSON 接口
714713
func (t *TimestampMicro) UnmarshalJSON(b []byte) error {
715-
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
714+
value := string(bytes.Trim(b, `"`))
716715
if value == "" || value == "null" {
717716
return nil
718717
}
@@ -757,7 +756,7 @@ func (t TimestampNano) MarshalJSON() ([]byte, error) {
757756
// UnmarshalJSON implements the interface json.Unmarshal for TimestampNano struct.
758757
// 实现 UnmarshalJSON 接口
759758
func (t *TimestampNano) UnmarshalJSON(b []byte) error {
760-
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
759+
value := string(bytes.Trim(b, `"`))
761760
if value == "" || value == "null" {
762761
return nil
763762
}

0 commit comments

Comments
 (0)