Skip to content

Commit f9b1a26

Browse files
committed
fix parse int
1 parent 2fd8054 commit f9b1a26

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

alibabacloud-gateway-sls/util/golang/client/log_serializer.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package client
22

33
import (
4+
"encoding/json"
45
"errors"
56
"fmt"
67
)
@@ -79,7 +80,7 @@ func serializeLogItem(lg *LogGroup, logItem interface{}) error {
7980

8081
logPb := &Log{}
8182

82-
time, exists, err := getInt64(m, "Time")
83+
time, exists, err := getInt(m, "Time")
8384
if err != nil {
8485
return err
8586
}
@@ -89,7 +90,7 @@ func serializeLogItem(lg *LogGroup, logItem interface{}) error {
8990
timeUint32 := uint32(time)
9091
logPb.Time = &timeUint32
9192

92-
if timeNano, exists, err := getInt64(m, "TimeNs"); err != nil {
93+
if timeNano, exists, err := getInt(m, "TimeNs"); err != nil {
9394
return err
9495
} else if exists {
9596
timeNanoUint32 := uint32(timeNano)
@@ -197,11 +198,20 @@ func getString(m map[string]interface{}, key string) (string, error) {
197198
return s, nil
198199
}
199200

200-
func getInt64(m map[string]interface{}, key string) (int64, bool, error) {
201+
func getInt(m map[string]interface{}, key string) (int64, bool, error) {
201202
v, ok := m[key]
202203
if !ok {
203204
return 0, false, nil
204205
}
206+
207+
if i, ok := v.(json.Number); ok {
208+
if vv, err := i.Int64(); err != nil {
209+
return 0, false, err
210+
} else {
211+
return vv, true, nil
212+
}
213+
}
214+
205215
if i, ok := v.(int64); ok {
206216
return i, true, nil
207217
}

0 commit comments

Comments
 (0)