Compare commits
2 Commits
v20220306.
...
v20220306.
Author | SHA1 | Date | |
---|---|---|---|
2dfdb1ad74 | |||
8d07304c03 |
1
.github/workflows/go.yml
vendored
1
.github/workflows/go.yml
vendored
@ -22,7 +22,6 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
git tag "v$(git show -s --format=%cd --date=format:%Y%m%d.%H%M%S)"
|
git tag "v$(git show -s --format=%cd --date=format:%Y%m%d.%H%M%S)"
|
||||||
git push --tags
|
git push --tags
|
||||||
sudo mv snyk-linux* /usr/local/bin/
|
|
||||||
|
|
||||||
- name: Release binaries with GoReleaser
|
- name: Release binaries with GoReleaser
|
||||||
uses: goreleaser/goreleaser-action@v2
|
uses: goreleaser/goreleaser-action@v2
|
||||||
|
9
main.go
9
main.go
@ -2,7 +2,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"github.com/go-ping/ping"
|
"github.com/go-ping/ping"
|
||||||
|
"github.com/rs/zerolog"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -13,10 +15,11 @@ import (
|
|||||||
var pings = make(map[string]time.Duration)
|
var pings = make(map[string]time.Duration)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
||||||
servers := getServers()
|
servers := getServers()
|
||||||
bestIndex := selectBestServerIndex(servers)
|
bestIndex := selectBestServerIndex(servers)
|
||||||
log.Info().Interface("best", servers[bestIndex]).Msg("Best Latency Server found.")
|
log.Debug().Interface("server", servers[bestIndex]).Msg("Best latency server found.")
|
||||||
|
fmt.Println(servers[bestIndex].Hostname)
|
||||||
}
|
}
|
||||||
|
|
||||||
func selectBestServerIndex(servers []server) int {
|
func selectBestServerIndex(servers []server) int {
|
||||||
@ -69,7 +72,7 @@ func serverLatency(s server) (time.Duration, error) {
|
|||||||
}
|
}
|
||||||
var duration time.Duration
|
var duration time.Duration
|
||||||
pinger.OnRecv = func(pkt *ping.Packet) {
|
pinger.OnRecv = func(pkt *ping.Packet) {
|
||||||
log.Info().Str("Server", s.Hostname).IPAddr("IP", pkt.IPAddr.IP).Dur("RTT", pkt.Rtt).Msg("Added server latency.")
|
log.Debug().Str("Server", s.Hostname).IPAddr("IP", pkt.IPAddr.IP).Dur("RTT", pkt.Rtt).Msg("Added server latency.")
|
||||||
duration = pkt.Rtt
|
duration = pkt.Rtt
|
||||||
}
|
}
|
||||||
err = pinger.Run()
|
err = pinger.Run()
|
||||||
|
Reference in New Issue
Block a user