mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-11 17:43:52 +00:00
37 lines
488 B
Go
37 lines
488 B
Go
|
package tsv
|
||
|
|
||
|
import (
|
||
|
"encoding/csv"
|
||
|
"io"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
type Writer struct {
|
||
|
file io.WriteCloser
|
||
|
|
||
|
*csv.Writer
|
||
|
}
|
||
|
|
||
|
func NewWriterFile(filename string) (*Writer, error) {
|
||
|
f, err := os.Create(filename)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return NewWriter(f), nil
|
||
|
}
|
||
|
|
||
|
func NewWriter(file io.WriteCloser) *Writer {
|
||
|
tsv := csv.NewWriter(file)
|
||
|
tsv.Comma = '\t'
|
||
|
return &Writer{
|
||
|
Writer: tsv,
|
||
|
file: file,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (w *Writer) Close() error {
|
||
|
w.Writer.Flush()
|
||
|
return w.file.Close()
|
||
|
}
|