-
Notifications
You must be signed in to change notification settings - Fork 0
/
stdout.go
60 lines (48 loc) · 1.38 KB
/
stdout.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package writer
import (
"context"
"io"
"log"
"os"
)
// StdoutWriter is a struct that implements the `Writer` interface for writing documents to STDOUT.
type StdoutWriter struct {
Writer
}
func init() {
ctx := context.Background()
err := RegisterWriter(ctx, "stdout", NewStdoutWriter)
if err != nil {
panic(err)
}
}
// NewStdoutWriter returns a new `CwdWriter` instance for writing documents to STDOUT configured by
// 'uri' in the form of:
//
// stdout://
//
// Technically 'uri' can also be an empty string.
func NewStdoutWriter(ctx context.Context, uri string) (Writer, error) {
wr := &StdoutWriter{}
return wr, nil
}
// Write copies the content of 'fh' to 'path' using an `os.Stdout` writer.
func (wr *StdoutWriter) Write(ctx context.Context, path string, fh io.ReadSeeker) (int64, error) {
return io.Copy(os.Stdout, fh)
}
// WriterURI returns the value of 'path'
func (wr *StdoutWriter) WriterURI(ctx context.Context, path string) string {
return path
}
// Flush is a no-op to conform to the `Writer` instance and returns nil.
func (wr *StdoutWriter) Flush(ctx context.Context) error {
return nil
}
// Close is a no-op to conform to the `Writer` instance and returns nil.
func (wr *StdoutWriter) Close(ctx context.Context) error {
return nil
}
// SetLogger assigns 'logger' to 'wr'.
func (wr *StdoutWriter) SetLogger(ctx context.Context, logger *log.Logger) error {
return nil
}