wip: output, pipe
This commit is contained in:
45
internal/controller/output/xfile/local.go
Normal file
45
internal/controller/output/xfile/local.go
Normal file
@ -0,0 +1,45 @@
|
||||
package xfile
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/loveuer/nfflow/internal/model"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
type LocalFile struct {
|
||||
writer io.Writer
|
||||
cfg struct {
|
||||
MaxSize int
|
||||
Path string
|
||||
}
|
||||
}
|
||||
|
||||
func (lf *LocalFile) init() error {
|
||||
var (
|
||||
err error
|
||||
)
|
||||
|
||||
if _, err = os.Stat(lf.cfg.Path); !os.IsNotExist(err) {
|
||||
return fmt.Errorf("file=%s already exist", lf.cfg.Path)
|
||||
}
|
||||
|
||||
if lf.writer, err = os.OpenFile(lf.cfg.Path, os.O_CREATE|os.O_RDWR, 0644); err != nil {
|
||||
return fmt.Errorf("openfile=%s err=%v", lf.cfg.Path, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lf *LocalFile) Start(ctx context.Context, rowCh <-chan *model.TaskRow, errCh chan<- error) error {
|
||||
var (
|
||||
err error
|
||||
)
|
||||
|
||||
if err = lf.init(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user