Skip to content

Commit 1356e6f

Browse files
authored
chore: tcp example (#38)
1 parent 9a889e2 commit 1356e6f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

examples/tcp.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"log/slog"
7+
"os"
8+
"time"
9+
10+
"github.com/jesusprubio/up/pkg"
11+
)
12+
13+
func main() {
14+
logger := slog.New(slog.NewTextHandler(os.Stderr, nil))
15+
probe := pkg.Probe{
16+
Protocols: []*pkg.Protocol{pkg.Protocols[1]},
17+
Count: 3,
18+
Timeout: 2 * time.Second,
19+
Logger: logger,
20+
ReportCh: make(chan *pkg.Report),
21+
}
22+
go func() {
23+
for report := range probe.ReportCh {
24+
fmt.Println(report)
25+
}
26+
}()
27+
err := probe.Run(context.Background())
28+
if err != nil {
29+
fmt.Printf("Error: %s\n", err)
30+
}
31+
}

0 commit comments

Comments
 (0)