-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_read_test.go
55 lines (44 loc) · 1.02 KB
/
example_read_test.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
// Copyright (c) 2023 Thierry FOURNIER (tfournier@arpalert.org)
package relp_test
import "io"
import "log"
import "net"
import "os"
import "github.com/thierry-f-78/go-relp"
// This is full example using io.ReadCloser interface with RELP library.
func Example_read() {
var ln net.Listener
var conn net.Conn
var err error
var opts *relp.Options
var r *relp.Relp
// Create and validate options
opts, err = relp.ValidateOptions(&relp.Options{
Tls: relp.Opt_tls_disabled,
})
if err != nil {
log.Fatalf(err.Error())
}
// Create listen connexion
ln, err = net.Listen("tcp", "0.0.0.0:4150")
if err != nil {
log.Fatalf(err.Error())
}
// accept connection
conn, err = ln.Accept()
if err != nil {
log.Fatalf(err.Error())
}
defer conn.Close()
// Create RELP from net.Conn
r, err = relp.NewTcp(conn, opts)
if err != nil {
log.Fatal(err.Error())
}
defer r.Close()
// Use io.ReadCloser interface to copy log from RELP stream to os.Stdout
_, err = io.Copy(os.Stdout, r)
if err != nil {
log.Fatal(err.Error())
}
}