init: basic tools
This commit is contained in:
29
input_mem.go
Normal file
29
input_mem.go
Normal file
@@ -0,0 +1,29 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user