diff options
author | Victor Häggqvist <[email protected]> | 2018-03-05 22:19:22 +0100 |
---|---|---|
committer | Victor Häggqvist <[email protected]> | 2018-03-05 22:19:22 +0100 |
commit | f96b7fc1e15ad88c80814e6b153c74453098f499 (patch) | |
tree | 92813eab3a38ad4f177bedef5e5c402bec8a9699 /vendor/github.com/gocarina/gocsv/safe_csv.go | |
parent | 6e1582f6e7f4148c25e58dc44a080d441e95db85 (diff) |
update vendor to use dep
Diffstat (limited to 'vendor/github.com/gocarina/gocsv/safe_csv.go')
-rw-r--r-- | vendor/github.com/gocarina/gocsv/safe_csv.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/vendor/github.com/gocarina/gocsv/safe_csv.go b/vendor/github.com/gocarina/gocsv/safe_csv.go new file mode 100644 index 0000000..4b2882f --- /dev/null +++ b/vendor/github.com/gocarina/gocsv/safe_csv.go @@ -0,0 +1,32 @@ +package gocsv + +//Wraps around SafeCSVWriter and makes it thread safe. +import ( + "encoding/csv" + "sync" +) + +type SafeCSVWriter struct { + *csv.Writer + m sync.Mutex +} + +func NewSafeCSVWriter(original *csv.Writer) *SafeCSVWriter { + return &SafeCSVWriter{ + Writer: original, + } +} + +//Override write +func (w *SafeCSVWriter) Write(row []string) error { + w.m.Lock() + defer w.m.Unlock() + return w.Writer.Write(row) +} + +//Override flush +func (w *SafeCSVWriter) Flush() { + w.m.Lock() + w.Writer.Flush() + w.m.Unlock() +} |