forked from moul/quicssh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
63 lines (58 loc) · 980 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
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"io"
"os"
"sync"
cli "github.com/urfave/cli/v2"
"golang.org/x/net/context"
)
func main() {
app := &cli.App{
Commands: []*cli.Command{
{
Name: "server",
Flags: []cli.Flag{
&cli.StringFlag{Name: "bind", Value: "localhost:4242"},
},
Action: server,
},
{
Name: "client",
Flags: []cli.Flag{
&cli.StringFlag{Name: "addr", Value: "localhost:4242"},
},
Action: client,
},
},
}
if err := app.Run(os.Args); err != nil {
panic(err)
}
}
func readAndWrite(ctx context.Context, r io.Reader, w io.Writer, wg *sync.WaitGroup) <-chan error {
c := make(chan error)
go func() {
if wg != nil {
defer wg.Done()
}
buff := make([]byte, 1024)
for {
select {
case <-ctx.Done():
return
default:
nr, err := r.Read(buff)
if err != nil {
return
}
if nr > 0 {
_, err := w.Write(buff[:nr])
if err != nil {
return
}
}
}
}
}()
return c
}