@@ -3,7 +3,6 @@ package carbon
3
3
import (
4
4
"bytes"
5
5
"database/sql/driver"
6
- "errors"
7
6
"fmt"
8
7
"strconv"
9
8
"time"
@@ -12,7 +11,7 @@ import (
12
11
// returns a failed scan error.
13
12
// 失败的扫描错误
14
13
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 )
16
15
}
17
16
18
17
// 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) {
48
47
// UnmarshalJSON implements the interface json.Unmarshal for Carbon struct.
49
48
// 实现 json.Unmarshaler 接口
50
49
func (c * Carbon ) UnmarshalJSON (b []byte ) error {
51
- value := fmt . Sprintf ( "%s" , bytes .Trim (b , `"` ))
50
+ value := string ( bytes .Trim (b , `"` ))
52
51
if value == "" || value == "null" {
53
52
return nil
54
53
}
@@ -89,7 +88,7 @@ func (t DateTime) MarshalJSON() ([]byte, error) {
89
88
// UnmarshalJSON implements the interface json.Unmarshal for DateTime struct.
90
89
// 实现 UnmarshalJSON 接口
91
90
func (t * DateTime ) UnmarshalJSON (b []byte ) error {
92
- value := fmt . Sprintf ( "%s" , bytes .Trim (b , `"` ))
91
+ value := string ( bytes .Trim (b , `"` ))
93
92
if value == "" || value == "null" {
94
93
return nil
95
94
}
@@ -133,7 +132,7 @@ func (t DateTimeMilli) MarshalJSON() ([]byte, error) {
133
132
// UnmarshalJSON implements the interface json.Unmarshal for DateTimeMilli struct.
134
133
// 实现 UnmarshalJSON 接口
135
134
func (t * DateTimeMilli ) UnmarshalJSON (b []byte ) error {
136
- value := fmt . Sprintf ( "%s" , bytes .Trim (b , `"` ))
135
+ value := string ( bytes .Trim (b , `"` ))
137
136
if value == "" || value == "null" {
138
137
return nil
139
138
}
@@ -177,7 +176,7 @@ func (t DateTimeMicro) MarshalJSON() ([]byte, error) {
177
176
// UnmarshalJSON implements the interface json.Unmarshal for DateTimeMicro struct.
178
177
// 实现 UnmarshalJSON 接口
179
178
func (t * DateTimeMicro ) UnmarshalJSON (b []byte ) error {
180
- value := fmt . Sprintf ( "%s" , bytes .Trim (b , `"` ))
179
+ value := string ( bytes .Trim (b , `"` ))
181
180
if value == "" || value == "null" {
182
181
return nil
183
182
}
@@ -221,7 +220,7 @@ func (t DateTimeNano) MarshalJSON() ([]byte, error) {
221
220
// UnmarshalJSON implements the interface json.Unmarshal for DateTimeNano struct.
222
221
// 实现 UnmarshalJSON 接口
223
222
func (t * DateTimeNano ) UnmarshalJSON (b []byte ) error {
224
- value := fmt . Sprintf ( "%s" , bytes .Trim (b , `"` ))
223
+ value := string ( bytes .Trim (b , `"` ))
225
224
if value == "" || value == "null" {
226
225
return nil
227
226
}
@@ -265,7 +264,7 @@ func (t Date) MarshalJSON() ([]byte, error) {
265
264
// UnmarshalJSON implements the interface json.Unmarshal for Date struct.
266
265
// 实现 UnmarshalJSON 接口
267
266
func (t * Date ) UnmarshalJSON (b []byte ) error {
268
- value := fmt . Sprintf ( "%s" , bytes .Trim (b , `"` ))
267
+ value := string ( bytes .Trim (b , `"` ))
269
268
if value == "" || value == "null" {
270
269
return nil
271
270
}
@@ -309,7 +308,7 @@ func (t DateMilli) MarshalJSON() ([]byte, error) {
309
308
// UnmarshalJSON implements the interface json.Unmarshal for DateMilli struct.
310
309
// 实现 UnmarshalJSON 接口
311
310
func (t * DateMilli ) UnmarshalJSON (b []byte ) error {
312
- value := fmt . Sprintf ( "%s" , bytes .Trim (b , `"` ))
311
+ value := string ( bytes .Trim (b , `"` ))
313
312
if value == "" || value == "null" {
314
313
return nil
315
314
}
@@ -353,7 +352,7 @@ func (t DateMicro) MarshalJSON() ([]byte, error) {
353
352
// UnmarshalJSON implements the interface json.Unmarshal for DateMicro struct.
354
353
// 实现 UnmarshalJSON 接口
355
354
func (t * DateMicro ) UnmarshalJSON (b []byte ) error {
356
- value := fmt . Sprintf ( "%s" , bytes .Trim (b , `"` ))
355
+ value := string ( bytes .Trim (b , `"` ))
357
356
if value == "" || value == "null" {
358
357
return nil
359
358
}
@@ -397,7 +396,7 @@ func (t DateNano) MarshalJSON() ([]byte, error) {
397
396
// UnmarshalJSON implements the interface json.Unmarshal for DateNano struct.
398
397
// 实现 UnmarshalJSON 接口
399
398
func (t * DateNano ) UnmarshalJSON (b []byte ) error {
400
- value := fmt . Sprintf ( "%s" , bytes .Trim (b , `"` ))
399
+ value := string ( bytes .Trim (b , `"` ))
401
400
if value == "" || value == "null" {
402
401
return nil
403
402
}
@@ -441,7 +440,7 @@ func (t Time) MarshalJSON() ([]byte, error) {
441
440
// UnmarshalJSON implements the interface json.Unmarshal for Time struct.
442
441
// 实现 UnmarshalJSON 接口
443
442
func (t * Time ) UnmarshalJSON (b []byte ) error {
444
- value := fmt . Sprintf ( "%s" , bytes .Trim (b , `"` ))
443
+ value := string ( bytes .Trim (b , `"` ))
445
444
if value == "" || value == "null" {
446
445
return nil
447
446
}
@@ -487,7 +486,7 @@ func (t TimeMilli) MarshalJSON() ([]byte, error) {
487
486
// UnmarshalJSON implements the interface json.Unmarshal for TimeMilli struct.
488
487
// 实现 UnmarshalJSON 接口
489
488
func (t * TimeMilli ) UnmarshalJSON (b []byte ) error {
490
- value := fmt . Sprintf ( "%s" , bytes .Trim (b , `"` ))
489
+ value := string ( bytes .Trim (b , `"` ))
491
490
if value == "" || value == "null" {
492
491
return nil
493
492
}
@@ -532,7 +531,7 @@ func (t TimeMicro) MarshalJSON() ([]byte, error) {
532
531
// UnmarshalJSON implements the interface json.Unmarshal for TimeMicro struct.
533
532
// 实现 UnmarshalJSON 接口
534
533
func (t * TimeMicro ) UnmarshalJSON (b []byte ) error {
535
- value := fmt . Sprintf ( "%s" , bytes .Trim (b , `"` ))
534
+ value := string ( bytes .Trim (b , `"` ))
536
535
if value == "" || value == "null" {
537
536
return nil
538
537
}
@@ -577,7 +576,7 @@ func (t TimeNano) MarshalJSON() ([]byte, error) {
577
576
// UnmarshalJSON implements the interface json.Unmarshal for TimeNano struct.
578
577
// 实现 UnmarshalJSON 接口
579
578
func (t * TimeNano ) UnmarshalJSON (b []byte ) error {
580
- value := fmt . Sprintf ( "%s" , bytes .Trim (b , `"` ))
579
+ value := string ( bytes .Trim (b , `"` ))
581
580
if value == "" || value == "null" {
582
581
return nil
583
582
}
@@ -622,7 +621,7 @@ func (t Timestamp) MarshalJSON() ([]byte, error) {
622
621
// UnmarshalJSON implements the interface json.Unmarshal for Timestamp struct.
623
622
// 实现 UnmarshalJSON 接口
624
623
func (t * Timestamp ) UnmarshalJSON (b []byte ) error {
625
- value := fmt . Sprintf ( "%s" , bytes .Trim (b , `"` ))
624
+ value := string ( bytes .Trim (b , `"` ))
626
625
if value == "" || value == "null" {
627
626
return nil
628
627
}
@@ -667,7 +666,7 @@ func (t TimestampMilli) MarshalJSON() ([]byte, error) {
667
666
// UnmarshalJSON implements the interface json.Unmarshal for TimestampMilli struct.
668
667
// 实现 UnmarshalJSON 接口
669
668
func (t * TimestampMilli ) UnmarshalJSON (b []byte ) error {
670
- value := fmt . Sprintf ( "%s" , bytes .Trim (b , `"` ))
669
+ value := string ( bytes .Trim (b , `"` ))
671
670
if value == "" || value == "null" {
672
671
return nil
673
672
}
@@ -712,7 +711,7 @@ func (t TimestampMicro) MarshalJSON() ([]byte, error) {
712
711
// UnmarshalJSON implements the interface json.Unmarshal for TimestampMicro struct.
713
712
// 实现 UnmarshalJSON 接口
714
713
func (t * TimestampMicro ) UnmarshalJSON (b []byte ) error {
715
- value := fmt . Sprintf ( "%s" , bytes .Trim (b , `"` ))
714
+ value := string ( bytes .Trim (b , `"` ))
716
715
if value == "" || value == "null" {
717
716
return nil
718
717
}
@@ -757,7 +756,7 @@ func (t TimestampNano) MarshalJSON() ([]byte, error) {
757
756
// UnmarshalJSON implements the interface json.Unmarshal for TimestampNano struct.
758
757
// 实现 UnmarshalJSON 接口
759
758
func (t * TimestampNano ) UnmarshalJSON (b []byte ) error {
760
- value := fmt . Sprintf ( "%s" , bytes .Trim (b , `"` ))
759
+ value := string ( bytes .Trim (b , `"` ))
761
760
if value == "" || value == "null" {
762
761
return nil
763
762
}
0 commit comments