(key string, value string)
| 87 | } |
| 88 | |
| 89 | func (s StructValue) Scan(key string, value string) error { |
| 90 | field, ok := s.spec.m[key] |
| 91 | if !ok { |
| 92 | return nil |
| 93 | } |
| 94 | |
| 95 | v := s.value.Field(field.index) |
| 96 | isPtr := v.Kind() == reflect.Ptr |
| 97 | |
| 98 | if isPtr && v.IsNil() { |
| 99 | v.Set(reflect.New(v.Type().Elem())) |
| 100 | } |
| 101 | if !isPtr && v.Type().Name() != "" && v.CanAddr() { |
| 102 | v = v.Addr() |
| 103 | isPtr = true |
| 104 | } |
| 105 | |
| 106 | if isPtr && v.Type().NumMethod() > 0 && v.CanInterface() { |
| 107 | switch scan := v.Interface().(type) { |
| 108 | case Scanner: |
| 109 | return scan.ScanRedis(value) |
| 110 | case encoding.TextUnmarshaler: |
| 111 | return scan.UnmarshalText(util.StringToBytes(value)) |
| 112 | case encoding.BinaryUnmarshaler: |
| 113 | return scan.UnmarshalBinary(util.StringToBytes(value)) |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | if isPtr { |
| 118 | v = v.Elem() |
| 119 | } |
| 120 | |
| 121 | if err := field.fn(v, value); err != nil { |
| 122 | t := s.value.Type() |
| 123 | return fmt.Errorf("cannot scan redis.result %s into struct field %s.%s of type %s, error-%s", |
| 124 | value, t.Name(), t.Field(field.index).Name, t.Field(field.index).Type, err.Error()) |
| 125 | } |
| 126 | return nil |
| 127 | } |
nothing calls this directly
no test coverage detected