-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
281 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package hello | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/avast/retry-go/v4" | ||
"github.com/go-ping/ping" | ||
) | ||
|
||
type pinger interface { | ||
Ping(address string) error | ||
} | ||
|
||
type defaultPinger struct{} | ||
|
||
func (p *defaultPinger) Ping(address string) error { | ||
pinger, pingerErr := ping.NewPinger(address) | ||
if pingerErr != nil { | ||
return fmt.Errorf("failed to create pinger: %v", pingerErr) | ||
} | ||
pinger.Count = 3 | ||
pinger.Timeout = 3 * time.Second | ||
runErr := pinger.Run() | ||
if runErr != nil { | ||
return fmt.Errorf("failed to run pinger: %v", runErr) | ||
} | ||
if pinger.Statistics().PacketsRecv == 0 { | ||
return fmt.Errorf("failed to ping server %s over the tunnel", address) | ||
} | ||
return nil | ||
} | ||
|
||
type retryingPinger struct { | ||
pinger pinger | ||
} | ||
|
||
// uses avast/retry-go to retry pings | ||
func (p *retryingPinger) Ping(address string) error { | ||
return retry.Do(func() error { | ||
return p.pinger.Ping(address) | ||
}, retry.Attempts(5), retry.Delay(time.Second)) | ||
} |
Oops, something went wrong.