allow full json output for best server using flag -o json
This commit is contained in:
parent
20e1092604
commit
230e89e2b7
@ -1,5 +1,5 @@
|
||||
# mullvad-best-server
|
||||
Determines the mullvat.net server with the lowest latency.
|
||||
Determines the mullvat.net wireguard server with the lowest latency.
|
||||
|
||||
## Installation
|
||||
|
||||
|
14
main.go
14
main.go
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/go-ping/ping"
|
||||
"github.com/rs/zerolog"
|
||||
@ -17,11 +18,22 @@ var pings = make(map[string]time.Duration)
|
||||
|
||||
func main() {
|
||||
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
||||
var outputFlag = flag.String("o", "short", "Output format. 'json' outputs server json")
|
||||
flag.Parse()
|
||||
|
||||
servers := getServers()
|
||||
bestIndex := selectBestServerIndex(servers)
|
||||
log.Debug().Interface("server", servers[bestIndex]).Msg("Best latency server found.")
|
||||
hostname := strings.Split(servers[bestIndex].Hostname, "-")[0]
|
||||
fmt.Println(hostname)
|
||||
if *outputFlag != "json" {
|
||||
fmt.Println(hostname)
|
||||
} else {
|
||||
serverJson, err := json.Marshal(servers[bestIndex])
|
||||
if err != nil {
|
||||
log.Fatal().Err(err)
|
||||
}
|
||||
fmt.Println(string(serverJson))
|
||||
}
|
||||
}
|
||||
|
||||
func selectBestServerIndex(servers []server) int {
|
||||
|
Reference in New Issue
Block a user