speedfast

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

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

Go to latest
Published: Mar 4, 2021 License: MIT Imports: 14 Imported by: 0

README

speedfast

Small GO library that tests the download and upload speeds by using Ookla's https://www.speedtest.net/ and Netflix's https://fast.com/

Used libs:

Dependency

go get github.com/calin014/speedfast
API Usage
package main

import (
	"fmt"

	"github.com/calin014/speedfast"
)

func main() {
	fmt.Println(speedfast.MeasureWithSpeedtest())
	fmt.Println(speedfast.MeasureWithFast())
	fmt.Println(speedfast.MeasureWithFastInHeadlessBrowser())

	// ...or use the Measurer interface
	measurers := []speedfast.Measurer{
		speedfast.MeasurerFunc(speedfast.MeasureWithSpeedtest),
		speedfast.MeasurerFunc(speedfast.MeasureWithFast),
		speedfast.MeasurerFunc(speedfast.MeasureWithFastInHeadlessBrowser),
	}

	for _, m := range measurers {
		fmt.Println(m.Measure())
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Measurement

type Measurement struct {
	Source           string
	Download, Upload float64
}

Measurement contains the result of network speed measurement

func MeasureWithFast

func MeasureWithFast() (Measurement, error)

MeasureWithFast naively attempts to measure network speed by using fast.com's api directly because fast-cli and go-fast libraries provide only download speed

func MeasureWithFastInHeadlessBrowser

func MeasureWithFastInHeadlessBrowser() (Measurement, error)

MeasureWithFastInHeadlessBrowser measures network speed by opening fast.com in a headless chrome browser and scraping the page

func MeasureWithSpeedtest

func MeasureWithSpeedtest() (Measurement, error)

MeasureWithSpeedtest measures network speed using speedtest.com's api

func (Measurement) String

func (measurement Measurement) String() string

type Measurer

type Measurer interface {
	Measure() (Measurement, error)
}

Measurer is the common interface for all the measurement functions

type MeasurerFunc

type MeasurerFunc func() (Measurement, error)

MeasurerFunc is used to create a Measurer from a function with the proper signature

func (MeasurerFunc) Measure

func (f MeasurerFunc) Measure() (Measurement, error)

Measure is MeasurerFunc implementation of Measurer

Jump to

Keyboard shortcuts

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