diff --git a/examples/tcp.go b/examples/tcp.go new file mode 100644 index 0000000..0ab0247 --- /dev/null +++ b/examples/tcp.go @@ -0,0 +1,31 @@ +package main + +import ( + "context" + "fmt" + "log/slog" + "os" + "time" + + "github.com/jesusprubio/up/pkg" +) + +func main() { + logger := slog.New(slog.NewTextHandler(os.Stderr, nil)) + probe := pkg.Probe{ + Protocols: []*pkg.Protocol{pkg.Protocols[1]}, + Count: 3, + Timeout: 2 * time.Second, + Logger: logger, + ReportCh: make(chan *pkg.Report), + } + go func() { + for report := range probe.ReportCh { + fmt.Println(report) + } + }() + err := probe.Run(context.Background()) + if err != nil { + fmt.Printf("Error: %s\n", err) + } +}