46 lines
736 B
Go
46 lines
736 B
Go
|
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
|
||
|
}
|