mirror of
https://github.com/davegallant/vpngate.git
synced 2025-08-05 08:13:41 +00:00
* Add survey library to select server * Add speedtest * Add --random flag to connect * Add list command * Cache server list * Tail the openvpn logs so that it appears in vpngate logs * Add goreleaser action * Add golangci-lint action
41 lines
789 B
Go
41 lines
789 B
Go
package cmd
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
|
|
"github.com/olekukonko/tablewriter"
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"github.com/davegallant/vpngate/pkg/vpn"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(listCmd)
|
|
}
|
|
|
|
var listCmd = &cobra.Command{
|
|
Use: "list",
|
|
Short: "List all available vpn servers",
|
|
Args: cobra.NoArgs,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
vpnServers, err := vpn.GetList()
|
|
|
|
if err != nil {
|
|
log.Fatal().Msgf(err.Error())
|
|
os.Exit(1)
|
|
}
|
|
|
|
table := tablewriter.NewWriter(os.Stdout)
|
|
table.SetHeader([]string{"#", "HostName", "Country", "Ping", "Score"})
|
|
|
|
for i, v := range *vpnServers {
|
|
table.Append([]string{strconv.Itoa(i + 1), v.HostName, v.CountryLong, v.Ping, strconv.Itoa(v.Score)})
|
|
}
|
|
table.Render() // Send output
|
|
|
|
},
|
|
}
|