decode.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. package dynamodbattribute
  2. import (
  3. "fmt"
  4. "reflect"
  5. "strconv"
  6. "time"
  7. "github.com/aws/aws-sdk-go/service/dynamodb"
  8. )
  9. // An Unmarshaler is an interface to provide custom unmarshaling of
  10. // AttributeValues. Use this to provide custom logic determining
  11. // how AttributeValues should be unmarshaled.
  12. // type ExampleUnmarshaler struct {
  13. // Value int
  14. // }
  15. //
  16. // type (u *exampleUnmarshaler) UnmarshalDynamoDBAttributeValue(av *dynamodb.AttributeValue) error {
  17. // if av.N == nil {
  18. // return nil
  19. // }
  20. //
  21. // n, err := strconv.ParseInt(*av.N, 10, 0)
  22. // if err != nil {
  23. // return err
  24. // }
  25. //
  26. // u.Value = n
  27. // return nil
  28. // }
  29. type Unmarshaler interface {
  30. UnmarshalDynamoDBAttributeValue(*dynamodb.AttributeValue) error
  31. }
  32. // Unmarshal will unmarshal DynamoDB AttributeValues to Go value types.
  33. // Both generic interface{} and concrete types are valid unmarshal
  34. // destination types.
  35. //
  36. // Unmarshal will allocate maps, slices, and pointers as needed to
  37. // unmarshal the AttributeValue into the provided type value.
  38. //
  39. // When unmarshaling AttributeValues into structs Unmarshal matches
  40. // the field names of the struct to the AttributeValue Map keys.
  41. // Initially it will look for exact field name matching, but will
  42. // fall back to case insensitive if not exact match is found.
  43. //
  44. // With the exception of omitempty, omitemptyelem, binaryset, numberset
  45. // and stringset all struct tags used by Marshal are also used by
  46. // Unmarshal.
  47. //
  48. // When decoding AttributeValues to interfaces Unmarshal will use the
  49. // following types.
  50. //
  51. // []byte, AV Binary (B)
  52. // [][]byte, AV Binary Set (BS)
  53. // bool, AV Boolean (BOOL)
  54. // []interface{}, AV List (L)
  55. // map[string]interface{}, AV Map (M)
  56. // float64, AV Number (N)
  57. // Number, AV Number (N) with UseNumber set
  58. // []float64, AV Number Set (NS)
  59. // []Number, AV Number Set (NS) with UseNumber set
  60. // string, AV String (S)
  61. // []string, AV String Set (SS)
  62. //
  63. // If the Decoder option, UseNumber is set numbers will be unmarshaled
  64. // as Number values instead of float64. Use this to maintain the original
  65. // string formating of the number as it was represented in the AttributeValue.
  66. // In addition provides additional opportunities to parse the number
  67. // string based on individual use cases.
  68. //
  69. // When unmarshaling any error that occurs will halt the unmarshal
  70. // and return the error.
  71. //
  72. // The output value provided must be a non-nil pointer
  73. func Unmarshal(av *dynamodb.AttributeValue, out interface{}) error {
  74. return NewDecoder().Decode(av, out)
  75. }
  76. // UnmarshalMap is an alias for Unmarshal which unmarshals from
  77. // a map of AttributeValues.
  78. //
  79. // The output value provided must be a non-nil pointer
  80. func UnmarshalMap(m map[string]*dynamodb.AttributeValue, out interface{}) error {
  81. return NewDecoder().Decode(&dynamodb.AttributeValue{M: m}, out)
  82. }
  83. // UnmarshalList is an alias for Unmarshal func which unmarshals
  84. // a slice of AttributeValues.
  85. //
  86. // The output value provided must be a non-nil pointer
  87. func UnmarshalList(l []*dynamodb.AttributeValue, out interface{}) error {
  88. return NewDecoder().Decode(&dynamodb.AttributeValue{L: l}, out)
  89. }
  90. // A Decoder provides unmarshaling AttributeValues to Go value types.
  91. type Decoder struct {
  92. MarshalOptions
  93. // Instructs the decoder to decode AttributeValue Numbers as
  94. // Number type instead of float64 when the destination type
  95. // is interface{}. Similar to encoding/json.Number
  96. UseNumber bool
  97. }
  98. // NewDecoder creates a new Decoder with default configuration. Use
  99. // the `opts` functional options to override the default configuration.
  100. func NewDecoder(opts ...func(*Decoder)) *Decoder {
  101. d := &Decoder{
  102. MarshalOptions: MarshalOptions{
  103. SupportJSONTags: true,
  104. },
  105. }
  106. for _, o := range opts {
  107. o(d)
  108. }
  109. return d
  110. }
  111. // Decode will unmarshal an AttributeValue into a Go value type. An error
  112. // will be return if the decoder is unable to unmarshal the AttributeValue
  113. // to the provide Go value type.
  114. //
  115. // The output value provided must be a non-nil pointer
  116. func (d *Decoder) Decode(av *dynamodb.AttributeValue, out interface{}, opts ...func(*Decoder)) error {
  117. v := reflect.ValueOf(out)
  118. if v.Kind() != reflect.Ptr || v.IsNil() || !v.IsValid() {
  119. return &InvalidUnmarshalError{Type: reflect.TypeOf(out)}
  120. }
  121. return d.decode(av, v, tag{})
  122. }
  123. var stringInterfaceMapType = reflect.TypeOf(map[string]interface{}(nil))
  124. var byteSliceType = reflect.TypeOf([]byte(nil))
  125. var byteSliceSlicetype = reflect.TypeOf([][]byte(nil))
  126. var numberType = reflect.TypeOf(Number(""))
  127. func (d *Decoder) decode(av *dynamodb.AttributeValue, v reflect.Value, fieldTag tag) error {
  128. var u Unmarshaler
  129. if av == nil || av.NULL != nil {
  130. u, v = indirect(v, true)
  131. if u != nil {
  132. return u.UnmarshalDynamoDBAttributeValue(av)
  133. }
  134. return d.decodeNull(v)
  135. }
  136. u, v = indirect(v, false)
  137. if u != nil {
  138. return u.UnmarshalDynamoDBAttributeValue(av)
  139. }
  140. switch {
  141. case len(av.B) != 0:
  142. return d.decodeBinary(av.B, v)
  143. case av.BOOL != nil:
  144. return d.decodeBool(av.BOOL, v)
  145. case len(av.BS) != 0:
  146. return d.decodeBinarySet(av.BS, v)
  147. case len(av.L) != 0:
  148. return d.decodeList(av.L, v)
  149. case len(av.M) != 0:
  150. return d.decodeMap(av.M, v)
  151. case av.N != nil:
  152. return d.decodeNumber(av.N, v)
  153. case len(av.NS) != 0:
  154. return d.decodeNumberSet(av.NS, v)
  155. case av.S != nil:
  156. return d.decodeString(av.S, v, fieldTag)
  157. case len(av.SS) != 0:
  158. return d.decodeStringSet(av.SS, v)
  159. }
  160. return nil
  161. }
  162. func (d *Decoder) decodeBinary(b []byte, v reflect.Value) error {
  163. if v.Kind() == reflect.Interface {
  164. buf := make([]byte, len(b))
  165. copy(buf, b)
  166. v.Set(reflect.ValueOf(buf))
  167. return nil
  168. }
  169. if v.Kind() != reflect.Slice {
  170. return &UnmarshalTypeError{Value: "binary", Type: v.Type()}
  171. }
  172. if v.Type() == byteSliceType {
  173. // Optimization for []byte types
  174. if v.IsNil() || v.Cap() < len(b) {
  175. v.Set(reflect.MakeSlice(byteSliceType, len(b), len(b)))
  176. } else if v.Len() != len(b) {
  177. v.SetLen(len(b))
  178. }
  179. copy(v.Interface().([]byte), b)
  180. return nil
  181. }
  182. switch v.Type().Elem().Kind() {
  183. case reflect.Uint8:
  184. // Fallback to reflection copy for type aliased of []byte type
  185. if v.IsNil() || v.Cap() < len(b) {
  186. v.Set(reflect.MakeSlice(v.Type(), len(b), len(b)))
  187. } else if v.Len() != len(b) {
  188. v.SetLen(len(b))
  189. }
  190. for i := 0; i < len(b); i++ {
  191. v.Index(i).SetUint(uint64(b[i]))
  192. }
  193. default:
  194. if v.Kind() == reflect.Array && v.Type().Elem().Kind() == reflect.Uint8 {
  195. reflect.Copy(v, reflect.ValueOf(b))
  196. break
  197. }
  198. return &UnmarshalTypeError{Value: "binary", Type: v.Type()}
  199. }
  200. return nil
  201. }
  202. func (d *Decoder) decodeBool(b *bool, v reflect.Value) error {
  203. switch v.Kind() {
  204. case reflect.Bool, reflect.Interface:
  205. v.Set(reflect.ValueOf(*b))
  206. default:
  207. return &UnmarshalTypeError{Value: "bool", Type: v.Type()}
  208. }
  209. return nil
  210. }
  211. func (d *Decoder) decodeBinarySet(bs [][]byte, v reflect.Value) error {
  212. switch v.Kind() {
  213. case reflect.Slice:
  214. // Make room for the slice elements if needed
  215. if v.IsNil() || v.Cap() < len(bs) {
  216. // What about if ignoring nil/empty values?
  217. v.Set(reflect.MakeSlice(v.Type(), 0, len(bs)))
  218. }
  219. case reflect.Array:
  220. // Limited to capacity of existing array.
  221. case reflect.Interface:
  222. set := make([][]byte, len(bs))
  223. for i, b := range bs {
  224. if err := d.decodeBinary(b, reflect.ValueOf(&set[i]).Elem()); err != nil {
  225. return err
  226. }
  227. }
  228. v.Set(reflect.ValueOf(set))
  229. return nil
  230. default:
  231. return &UnmarshalTypeError{Value: "binary set", Type: v.Type()}
  232. }
  233. for i := 0; i < v.Cap() && i < len(bs); i++ {
  234. v.SetLen(i + 1)
  235. u, elem := indirect(v.Index(i), false)
  236. if u != nil {
  237. return u.UnmarshalDynamoDBAttributeValue(&dynamodb.AttributeValue{BS: bs})
  238. }
  239. if err := d.decodeBinary(bs[i], elem); err != nil {
  240. return err
  241. }
  242. }
  243. return nil
  244. }
  245. func (d *Decoder) decodeNumber(n *string, v reflect.Value) error {
  246. switch v.Kind() {
  247. case reflect.Interface:
  248. i, err := d.decodeNumberToInterface(n)
  249. if err != nil {
  250. return err
  251. }
  252. v.Set(reflect.ValueOf(i))
  253. return nil
  254. case reflect.String:
  255. if v.Type() == numberType { // Support Number value type
  256. v.Set(reflect.ValueOf(Number(*n)))
  257. return nil
  258. }
  259. v.Set(reflect.ValueOf(*n))
  260. case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
  261. i, err := strconv.ParseInt(*n, 10, 64)
  262. if err != nil {
  263. return err
  264. }
  265. if v.OverflowInt(i) {
  266. return &UnmarshalTypeError{
  267. Value: fmt.Sprintf("number overflow, %s", *n),
  268. Type: v.Type(),
  269. }
  270. }
  271. v.SetInt(i)
  272. case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
  273. i, err := strconv.ParseUint(*n, 10, 64)
  274. if err != nil {
  275. return err
  276. }
  277. if v.OverflowUint(i) {
  278. return &UnmarshalTypeError{
  279. Value: fmt.Sprintf("number overflow, %s", *n),
  280. Type: v.Type(),
  281. }
  282. }
  283. v.SetUint(i)
  284. case reflect.Float32, reflect.Float64:
  285. i, err := strconv.ParseFloat(*n, 64)
  286. if err != nil {
  287. return err
  288. }
  289. if v.OverflowFloat(i) {
  290. return &UnmarshalTypeError{
  291. Value: fmt.Sprintf("number overflow, %s", *n),
  292. Type: v.Type(),
  293. }
  294. }
  295. v.SetFloat(i)
  296. default:
  297. return &UnmarshalTypeError{Value: "number", Type: v.Type()}
  298. }
  299. return nil
  300. }
  301. func (d *Decoder) decodeNumberToInterface(n *string) (interface{}, error) {
  302. if d.UseNumber {
  303. return Number(*n), nil
  304. }
  305. // Default to float64 for all numbers
  306. return strconv.ParseFloat(*n, 64)
  307. }
  308. func (d *Decoder) decodeNumberSet(ns []*string, v reflect.Value) error {
  309. switch v.Kind() {
  310. case reflect.Slice:
  311. // Make room for the slice elements if needed
  312. if v.IsNil() || v.Cap() < len(ns) {
  313. // What about if ignoring nil/empty values?
  314. v.Set(reflect.MakeSlice(v.Type(), 0, len(ns)))
  315. }
  316. case reflect.Array:
  317. // Limited to capacity of existing array.
  318. case reflect.Interface:
  319. if d.UseNumber {
  320. set := make([]Number, len(ns))
  321. for i, n := range ns {
  322. if err := d.decodeNumber(n, reflect.ValueOf(&set[i]).Elem()); err != nil {
  323. return err
  324. }
  325. }
  326. v.Set(reflect.ValueOf(set))
  327. } else {
  328. set := make([]float64, len(ns))
  329. for i, n := range ns {
  330. if err := d.decodeNumber(n, reflect.ValueOf(&set[i]).Elem()); err != nil {
  331. return err
  332. }
  333. }
  334. v.Set(reflect.ValueOf(set))
  335. }
  336. return nil
  337. default:
  338. return &UnmarshalTypeError{Value: "number set", Type: v.Type()}
  339. }
  340. for i := 0; i < v.Cap() && i < len(ns); i++ {
  341. v.SetLen(i + 1)
  342. u, elem := indirect(v.Index(i), false)
  343. if u != nil {
  344. return u.UnmarshalDynamoDBAttributeValue(&dynamodb.AttributeValue{NS: ns})
  345. }
  346. if err := d.decodeNumber(ns[i], elem); err != nil {
  347. return err
  348. }
  349. }
  350. return nil
  351. }
  352. func (d *Decoder) decodeList(avList []*dynamodb.AttributeValue, v reflect.Value) error {
  353. switch v.Kind() {
  354. case reflect.Slice:
  355. // Make room for the slice elements if needed
  356. if v.IsNil() || v.Cap() < len(avList) {
  357. // What about if ignoring nil/empty values?
  358. v.Set(reflect.MakeSlice(v.Type(), 0, len(avList)))
  359. }
  360. case reflect.Array:
  361. // Limited to capacity of existing array.
  362. case reflect.Interface:
  363. s := make([]interface{}, len(avList))
  364. for i, av := range avList {
  365. if err := d.decode(av, reflect.ValueOf(&s[i]).Elem(), tag{}); err != nil {
  366. return err
  367. }
  368. }
  369. v.Set(reflect.ValueOf(s))
  370. return nil
  371. default:
  372. return &UnmarshalTypeError{Value: "list", Type: v.Type()}
  373. }
  374. // If v is not a slice, array
  375. for i := 0; i < v.Cap() && i < len(avList); i++ {
  376. v.SetLen(i + 1)
  377. if err := d.decode(avList[i], v.Index(i), tag{}); err != nil {
  378. return err
  379. }
  380. }
  381. return nil
  382. }
  383. func (d *Decoder) decodeMap(avMap map[string]*dynamodb.AttributeValue, v reflect.Value) error {
  384. switch v.Kind() {
  385. case reflect.Map:
  386. t := v.Type()
  387. if t.Key().Kind() != reflect.String {
  388. return &UnmarshalTypeError{Value: "map string key", Type: t.Key()}
  389. }
  390. if v.IsNil() {
  391. v.Set(reflect.MakeMap(t))
  392. }
  393. case reflect.Struct:
  394. case reflect.Interface:
  395. v.Set(reflect.MakeMap(stringInterfaceMapType))
  396. v = v.Elem()
  397. default:
  398. return &UnmarshalTypeError{Value: "map", Type: v.Type()}
  399. }
  400. if v.Kind() == reflect.Map {
  401. for k, av := range avMap {
  402. key := reflect.ValueOf(k)
  403. elem := reflect.New(v.Type().Elem()).Elem()
  404. if err := d.decode(av, elem, tag{}); err != nil {
  405. return err
  406. }
  407. v.SetMapIndex(key, elem)
  408. }
  409. } else if v.Kind() == reflect.Struct {
  410. fields := unionStructFields(v.Type(), d.MarshalOptions)
  411. for k, av := range avMap {
  412. if f, ok := fieldByName(fields, k); ok {
  413. fv := v.FieldByIndex(f.Index)
  414. if err := d.decode(av, fv, f.tag); err != nil {
  415. return err
  416. }
  417. }
  418. }
  419. }
  420. return nil
  421. }
  422. func (d *Decoder) decodeNull(v reflect.Value) error {
  423. if v.IsValid() && v.CanSet() {
  424. v.Set(reflect.Zero(v.Type()))
  425. }
  426. return nil
  427. }
  428. func (d *Decoder) decodeString(s *string, v reflect.Value, fieldTag tag) error {
  429. if fieldTag.AsString {
  430. return d.decodeNumber(s, v)
  431. }
  432. // To maintain backwards compatibility with ConvertFrom family of methods which
  433. // converted strings to time.Time structs
  434. if _, ok := v.Interface().(time.Time); ok {
  435. t, err := time.Parse(time.RFC3339, *s)
  436. if err != nil {
  437. return err
  438. }
  439. v.Set(reflect.ValueOf(t))
  440. return nil
  441. }
  442. switch v.Kind() {
  443. case reflect.String:
  444. v.SetString(*s)
  445. case reflect.Interface:
  446. // Ensure type aliasing is handled properly
  447. v.Set(reflect.ValueOf(*s).Convert(v.Type()))
  448. default:
  449. return &UnmarshalTypeError{Value: "string", Type: v.Type()}
  450. }
  451. return nil
  452. }
  453. func (d *Decoder) decodeStringSet(ss []*string, v reflect.Value) error {
  454. switch v.Kind() {
  455. case reflect.Slice:
  456. // Make room for the slice elements if needed
  457. if v.IsNil() || v.Cap() < len(ss) {
  458. v.Set(reflect.MakeSlice(v.Type(), 0, len(ss)))
  459. }
  460. case reflect.Array:
  461. // Limited to capacity of existing array.
  462. case reflect.Interface:
  463. set := make([]string, len(ss))
  464. for i, s := range ss {
  465. if err := d.decodeString(s, reflect.ValueOf(&set[i]).Elem(), tag{}); err != nil {
  466. return err
  467. }
  468. }
  469. v.Set(reflect.ValueOf(set))
  470. return nil
  471. default:
  472. return &UnmarshalTypeError{Value: "string set", Type: v.Type()}
  473. }
  474. for i := 0; i < v.Cap() && i < len(ss); i++ {
  475. v.SetLen(i + 1)
  476. u, elem := indirect(v.Index(i), false)
  477. if u != nil {
  478. return u.UnmarshalDynamoDBAttributeValue(&dynamodb.AttributeValue{SS: ss})
  479. }
  480. if err := d.decodeString(ss[i], elem, tag{}); err != nil {
  481. return err
  482. }
  483. }
  484. return nil
  485. }
  486. // indirect will walk a value's interface or pointer value types. Returning
  487. // the final value or the value a unmarshaler is defined on.
  488. //
  489. // Based on the enoding/json type reflect value type indirection in Go Stdlib
  490. // https://golang.org/src/encoding/json/decode.go indirect func.
  491. func indirect(v reflect.Value, decodingNull bool) (Unmarshaler, reflect.Value) {
  492. if v.Kind() != reflect.Ptr && v.Type().Name() != "" && v.CanAddr() {
  493. v = v.Addr()
  494. }
  495. for {
  496. if v.Kind() == reflect.Interface && !v.IsNil() {
  497. e := v.Elem()
  498. if e.Kind() == reflect.Ptr && !e.IsNil() && (!decodingNull || e.Elem().Kind() == reflect.Ptr) {
  499. v = e
  500. continue
  501. }
  502. }
  503. if v.Kind() != reflect.Ptr {
  504. break
  505. }
  506. if v.Elem().Kind() != reflect.Ptr && decodingNull && v.CanSet() {
  507. break
  508. }
  509. if v.IsNil() {
  510. v.Set(reflect.New(v.Type().Elem()))
  511. }
  512. if v.Type().NumMethod() > 0 {
  513. if u, ok := v.Interface().(Unmarshaler); ok {
  514. return u, reflect.Value{}
  515. }
  516. }
  517. v = v.Elem()
  518. }
  519. return nil, v
  520. }
  521. // A Number represents a Attributevalue number literal.
  522. type Number string
  523. // Float64 attempts to cast the number ot a float64, returning
  524. // the result of the case or error if the case failed.
  525. func (n Number) Float64() (float64, error) {
  526. return strconv.ParseFloat(string(n), 64)
  527. }
  528. // Int64 attempts to cast the number ot a int64, returning
  529. // the result of the case or error if the case failed.
  530. func (n Number) Int64() (int64, error) {
  531. return strconv.ParseInt(string(n), 10, 64)
  532. }
  533. // Uint64 attempts to cast the number ot a uint64, returning
  534. // the result of the case or error if the case failed.
  535. func (n Number) Uint64() (uint64, error) {
  536. return strconv.ParseUint(string(n), 10, 64)
  537. }
  538. // String returns the raw number represented as a string
  539. func (n Number) String() string {
  540. return string(n)
  541. }
  542. type emptyOrigError struct{}
  543. func (e emptyOrigError) OrigErr() error {
  544. return nil
  545. }
  546. // An UnmarshalTypeError is an error type representing a error
  547. // unmarshaling the AttributeValue's element to a Go value type.
  548. // Includes details about the AttributeValue type and Go value type.
  549. type UnmarshalTypeError struct {
  550. emptyOrigError
  551. Value string
  552. Type reflect.Type
  553. }
  554. // Error returns the string representation of the error.
  555. // satisfying the error interface
  556. func (e *UnmarshalTypeError) Error() string {
  557. return fmt.Sprintf("%s: %s", e.Code(), e.Message())
  558. }
  559. // Code returns the code of the error, satisfying the awserr.Error
  560. // interface.
  561. func (e *UnmarshalTypeError) Code() string {
  562. return "UnmarshalTypeError"
  563. }
  564. // Message returns the detailed message of the error, satisfying
  565. // the awserr.Error interface.
  566. func (e *UnmarshalTypeError) Message() string {
  567. return "cannot unmarshal " + e.Value + " into Go value of type " + e.Type.String()
  568. }
  569. // An InvalidUnmarshalError is an error type representing an invalid type
  570. // encountered while unmarshaling a AttributeValue to a Go value type.
  571. type InvalidUnmarshalError struct {
  572. emptyOrigError
  573. Type reflect.Type
  574. }
  575. // Error returns the string representation of the error.
  576. // satisfying the error interface
  577. func (e *InvalidUnmarshalError) Error() string {
  578. return fmt.Sprintf("%s: %s", e.Code(), e.Message())
  579. }
  580. // Code returns the code of the error, satisfying the awserr.Error
  581. // interface.
  582. func (e *InvalidUnmarshalError) Code() string {
  583. return "InvalidUnmarshalError"
  584. }
  585. // Message returns the detailed message of the error, satisfying
  586. // the awserr.Error interface.
  587. func (e *InvalidUnmarshalError) Message() string {
  588. if e.Type == nil {
  589. return "cannot unmarshal to nil value"
  590. }
  591. if e.Type.Kind() != reflect.Ptr {
  592. return "cannot unmasrhal to non-pointer value, got " + e.Type.String()
  593. }
  594. return "cannot unmarshal to nil value, " + e.Type.String()
  595. }