1
0
mirror of https://github.com/redis/go-redis.git synced 2025-08-07 12:42:55 +03:00

feat(scan): scan time.Time sets the default decoding (#2413)

* feat(scan): scan time.Time uses `UnmarshalText(RFC3339)` interface decoding by default
This commit is contained in:
Monkey
2023-02-07 20:23:39 +08:00
committed by GitHub
parent 9d5e48507e
commit 8db6eeed27
3 changed files with 38 additions and 1 deletions

View File

@@ -1,10 +1,13 @@
package hscan
import (
"encoding"
"fmt"
"reflect"
"strings"
"sync"
"github.com/redis/go-redis/v9/internal/util"
)
// structMap contains the map of struct fields for target structs
@@ -97,8 +100,11 @@ func (s StructValue) Scan(key string, value string) error {
}
if isPtr && v.Type().NumMethod() > 0 && v.CanInterface() {
if scan, ok := v.Interface().(Scanner); ok {
switch scan := v.Interface().(type) {
case Scanner:
return scan.ScanRedis(value)
case encoding.TextUnmarshaler:
return scan.UnmarshalText(util.StringToBytes(value))
}
}