elasticstream/source/elastic/read.go

33 lines
542 B
Go
Raw Normal View History

2024-10-07 15:25:13 +05:30
package elastic
import (
"context"
)
func (c *Client) Read(context.Context) (*Data, error) {
data, ok := <-c.ch
if !ok {
return nil, fmt.Errorf("error reading data from channel")
}
index := data.Header.Index
if !ok {
return nil, fmt.Errorf("error index not found in data header")
}
offset, ok := c.offsets[index]
if !ok {
return nil, fmt.Errorf("error offset index not found")
}
c.offsets[index] = offset + 1
err := setOffset(c.db, index, c.offsets[index])
if err != nil {
return nil, err
}
return &data, nil
}