-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Decoder
Oliver Eilhard edited this page Feb 22, 2015
·
2 revisions
Elastic enables you to use your own decoder for deserializing JSON data as received from Elasticsearch. Use client.SetDecoder(...)
to implement your own.
Here is an example:
// CountingDecoder needs to implement the elastic.Decoder interface.
type CountingDecoder struct {
dec json.Decoder
N int64
}
func (d *CountingDecoder) Decode(data []byte, v interface{}) error {
atomic.AddInt64(&d.N, 1)
return json.NewDecoder(bytes.NewReader(data)).Decode(v)
}
...
client.SetDecoder(&CountingDecoder{})