diff --git a/README.md b/README.md index 1fb02fc..834e106 100644 --- a/README.md +++ b/README.md @@ -24,13 +24,24 @@ if err != nil { os.Exit(1) } p.AddIPAddr(ra) -p.AddHandler("receive", func(addr *net.IPAddr, rtt time.Duration) { +err = p.AddHandler("receive", func(addr *net.IPAddr, rtt time.Duration) { fmt.Printf("IP Addr: %s receive, RTT: %v\n", addr.String(), rtt) }) -p.AddHandler("idle", func() { +if err != nil { + fmt.Println(err) + os.Exit(1) +} +err = p.AddHandler("idle", func() { fmt.Println("finish") }) -p.Run() +if err != nil { + fmt.Println(err) + os.Exit(1) +} +err = p.Run() +if err != nil { + fmt.Println(err) +} ``` It sends an ICMP packet and wait a response. If it receives a response, it diff --git a/fastping.go b/fastping.go index 69838df..fcf5ec7 100644 --- a/fastping.go +++ b/fastping.go @@ -15,13 +15,24 @@ // os.Exit(1) // } // p.AddIPAddr(ra) -// p.AddHandler("receive", func(addr *net.IPAddr, rtt time.Duration) { +// err = p.AddHandler("receive", func(addr *net.IPAddr, rtt time.Duration) { // fmt.Printf("IP Addr: %s receive, RTT: %v\n", addr.String(), rtt) // }) -// p.AddHandler("idle", func() { +// if err != nil { +// fmt.Println(err) +// os.Exit(1) +// } +// err = p.AddHandler("idle", func() { // fmt.Println("finish") // }) -// p.Run() +// if err != nil { +// fmt.Println(err) +// os.Exit(1) +// } +// err = p.Run() +// if err != nil { +// fmt.Println(err) +// } // // It sends an ICMP packet and wait a response. If it receives a response, // it calls "receive" callback. After that, MaxRTT time passed, it calls