-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstdin.go
More file actions
53 lines (42 loc) · 1.27 KB
/
stdin.go
File metadata and controls
53 lines (42 loc) · 1.27 KB
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
package reader
import (
"context"
"github.com/whosonfirst/go-ioutil"
"io"
"os"
)
// Constant string value representing STDIN.
const STDIN string = "-"
// StdinReader is a struct that implements the `Reader` interface for reading documents from STDIN.
type StdinReader struct {
Reader
}
func init() {
ctx := context.Background()
err := RegisterReader(ctx, "stdin", NewStdinReader)
if err != nil {
panic(err)
}
}
// NewStdinReader returns a new `Reader` instance for reading documents from STDIN,
// configured by 'uri' in the form of:
//
// stdin://
//
// Technically 'uri' can also be an empty string.
func NewStdinReader(ctx context.Context, uri string) (Reader, error) {
r := &StdinReader{}
return r, nil
}
// Read will open a `io.ReadSeekCloser` instance wrapping `os.Stdin`.
func (r *StdinReader) Read(ctx context.Context, uri string) (io.ReadSeekCloser, error) {
return ioutil.NewReadSeekCloser(os.Stdin)
}
// Exists returns a boolean value indicating whether 'path' already exists (meaning it will always return false).
func (r *StdinReader) Exists(ctx context.Context, path string) (bool, error) {
return false, nil
}
// ReaderURI will return the value of the `STDIN` constant.
func (r *StdinReader) ReaderURI(ctx context.Context, uri string) string {
return STDIN
}