-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
50 lines (37 loc) · 771 Bytes
/
main.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
package main
import (
"fmt"
"os"
"io"
"log"
"io/ioutil"
"strings"
"regexp"
)
func cat(r io.Reader) ([]byte, error) {
data, err := ioutil.ReadAll(r)
if (err != nil) {
return nil, err
}
return data, nil
}
func main() {
var output []byte
var err error
args := os.Args[1:]
if len(args) > 0 {
concat := strings.Join(os.Args[1:], " ")
data := strings.NewReader(concat)
output, err = cat(data)
if err != nil {
log.Panic(err)
}
fmt.Print(regexp.QuoteMeta(string(output)))
} else {
output, err = cat(os.Stdin)
if err != nil {
log.Panic(err)
}
fmt.Print(regexp.QuoteMeta(string(output)))
}
}