aboutsummaryrefslogtreecommitdiff
path: root/lib/dsv/writerinterface.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2018-09-17 03:48:37 +0700
committerShulhan <ms@kilabit.info>2018-09-18 01:50:21 +0700
commit446fef94cd712861221c0098dcdd9ae52aaed0eb (patch)
tree63167d5a90b27121b552ab428f337717bcf2b01f /lib/dsv/writerinterface.go
parent44b26edf7f390db383fe025454be0c4e30cfbd9b (diff)
downloadpakakeh.go-446fef94cd712861221c0098dcdd9ae52aaed0eb.tar.xz
Merge package "github.com/shuLhan/dsv"
Diffstat (limited to 'lib/dsv/writerinterface.go')
-rw-r--r--lib/dsv/writerinterface.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/dsv/writerinterface.go b/lib/dsv/writerinterface.go
new file mode 100644
index 00000000..e2b8856c
--- /dev/null
+++ b/lib/dsv/writerinterface.go
@@ -0,0 +1,45 @@
+// Copyright 2015-2018, Shulhan <ms@kilabit.info>. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package dsv
+
+//
+// WriterInterface is an interface for writing DSV data to file.
+//
+type WriterInterface interface {
+ ConfigInterface
+ GetOutput() string
+ SetOutput(path string)
+ OpenOutput(file string) error
+ Flush() error
+ Close() error
+}
+
+//
+// OpenWriter configuration file and initialize the attributes.
+//
+func OpenWriter(writer WriterInterface, fcfg string) (e error) {
+ e = ConfigOpen(writer, fcfg)
+ if e != nil {
+ return
+ }
+
+ return InitWriter(writer)
+}
+
+//
+// InitWriter initialize writer by opening output file.
+//
+func InitWriter(writer WriterInterface) error {
+ out := writer.GetOutput()
+
+ // Exit immediately if no output file is defined in config.
+ if "" == out {
+ return ErrNoOutput
+ }
+
+ writer.SetOutput(ConfigCheckPath(writer, out))
+
+ return writer.OpenOutput("")
+}