decoder.go 820 B

1234567891011121314151617181920212223242526
  1. // Copyright 2012-present Oliver Eilhard. All rights reserved.
  2. // Use of this source code is governed by a MIT-license.
  3. // See http://olivere.mit-license.org/license.txt for details.
  4. package elastic
  5. import (
  6. "encoding/json"
  7. )
  8. // Decoder is used to decode responses from Elasticsearch.
  9. // Users of elastic can implement their own marshaler for advanced purposes
  10. // and set them per Client (see SetDecoder). If none is specified,
  11. // DefaultDecoder is used.
  12. type Decoder interface {
  13. Decode(data []byte, v interface{}) error
  14. }
  15. // DefaultDecoder uses json.Unmarshal from the Go standard library
  16. // to decode JSON data.
  17. type DefaultDecoder struct{}
  18. // Decode decodes with json.Unmarshal from the Go standard library.
  19. func (u *DefaultDecoder) Decode(data []byte, v interface{}) error {
  20. return json.Unmarshal(data, v)
  21. }