30 lines
391 B
Go
30 lines
391 B
Go
|
package script
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"io"
|
||
|
)
|
||
|
|
||
|
type MemReader struct {
|
||
|
rows [][]string
|
||
|
curr int
|
||
|
}
|
||
|
|
||
|
func NewMemReader(records [][]string) *MemReader {
|
||
|
return &MemReader{
|
||
|
rows: records,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (m *MemReader) Read(context.Context) ([]string, error) {
|
||
|
if m.curr == len(m.rows) || len(m.rows) == 0 {
|
||
|
return nil, io.EOF
|
||
|
}
|
||
|
|
||
|
defer func() {
|
||
|
m.curr++
|
||
|
}()
|
||
|
|
||
|
return m.rows[m.curr], nil
|
||
|
}
|