GoSpeedTest

package module
v0.0.0-...-cad5e10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 31, 2021 License: AGPL-3.0 Imports: 3 Imported by: 0

README

GoSpeedTest

An easier way to run a speedtest from your Go application

Installation

go get -u github.com/LucaTheHacker/GoSpeedTest

Requirements

In order to use GoSpeedTest you'll need to have SpeedTest CLI installed on your system available under the command speedtest. Remember also to run at least one speedtest, otherwise you won't accept the licenses.

Usage

package main
import (
	"fmt"
	"github.com/LucaTheHacker/GoSpeedTest"
)

func main() {
	servers, err := GoSpeedTest.GetServers()
	if err != nil {
		panic(err)
	}

	result, err := GoSpeedTest.SpeedTest(servers[0].ID)
	if err != nil {
		panic(err)
	}
	fmt.Printf("--- SpeedTest result ---\nServerID: %d\nDownload: %.2fmbps\nUpload: %.2fmbps\nPing: %.2fms\nJitter: %.2fms\nPacketLoss: %.2f%%",
		result.Server.ID, result.Download.GetMegaBit(), result.Upload.GetMegaBit(), result.Ping.Latency, result.Ping.Jitter, result.PacketLoss)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Location = "speedtest"

Functions

This section is empty.

Types

type Interface

type Interface struct {
	InternalIP string `json:"internalIp"`
	Name       string `json:"name"`
	MacAddress string `json:"macAddr"`
	IsVPN      bool   `json:"isVpn"`
	ExternalIP string `json:"externalIp"`
}

Interface contains data about the interface used to run the speedtest

type Measure

type Measure struct {
	Bandwidth int `json:"bandwidth"`
	Bytes     int `json:"bytes"`
	Elapsed   int `json:"elapsed"`
}

Measure contains data for Download and Upload

func (*Measure) GetGigaBit

func (m *Measure) GetGigaBit() float64

GetGigaBit returns Measure speed in GigaBits

func (*Measure) GetMegaBit

func (m *Measure) GetMegaBit() float64

GetMegaBit returns Measure speed in MegaBits

func (*Measure) GetMegaByte

func (m *Measure) GetMegaByte() float64

GetMegaByte returns Measure speed in MegaBytes

type Ping

type Ping struct {
	Jitter  float32 `json:"jitter"`
	Latency float32 `json:"latency"`
}

Ping contains data for ping

type Result

type Result struct {
	Type       string    `json:"type"`
	Timestamp  string    `json:"timestamp"`
	Ping       Ping      `json:"ping"`
	Download   Measure   `json:"download"`
	Upload     Measure   `json:"upload"`
	PacketLoss float64   `json:"packetLoss"`
	ISP        string    `json:"isp"`
	Interface  Interface `json:"interface"`
	Server     Server    `json:"server"`
	Servers    []Server  `json:"servers"`
	Result     SResult   `json:"result"`
}

Result contains data from CLI output

func SpeedTest

func SpeedTest(serverID int) (result *Result, err error)

SpeedTest runs a speedtest using Ookla. SpeedTest from Ookla needs to be installed in order to run this command. (https://www.speedtest.net/apps/cli)

type SResult

type SResult struct {
	ID  string `json:"id"`
	URL string `json:"url"`
}

SResult contains data for speedtest share

type Server

type Server struct {
	ID       int    `json:"id"`
	Name     string `json:"name"`
	Location string `json:"location"`
	Country  string `json:"country"`
	Host     string `json:"host"`
	Port     int    `json:"port"`
	IP       string `json:"ip"`
}

Server contains data about the server used to run the speedtest

func GetServers

func GetServers() ([]Server, error)

GetServers returns a list of servers recommended (bu Ookla) to run a Speedtest.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL