Skip to content

Latest commit

 

History

History
61 lines (45 loc) · 1.09 KB

README.md

File metadata and controls

61 lines (45 loc) · 1.09 KB

gost

Go API to Test Internet Speed using speedtest.net or fast.com

API Usage

The code below tests download and upload speeds using speedtest.net and fast.com.

package main

import (
	"context"
	"fmt"

	"github.com/user358/gost"
)

func main() {
	stProvider, err := gost.NewSpeedTestProvider()
	if err != nil {
		panic(err)
	}

	stResult, err := gost.Measure(context.Background(), stProvider)
	if err != nil {
		panic(err)
	}

	fmt.Printf("speedtest.net download: %5.2f Mbit/s\n", stResult.Download)
	fmt.Printf("speedtest.net upload: %5.2f Mbit/s\n\n", stResult.Upload)

	fastProvider, err := gost.NewFastProvider(false, nil)
	if err != nil {
		panic(err)
	}

	fastResult, err := gost.Measure(context.Background(), fastProvider)
	if err != nil {
		panic(err)
	}

	fmt.Printf("fast.com download: %5.2f Mbit/s\n", fastResult.Download)
	fmt.Printf("fast.com upload: %5.2f Mbit/s\n\n", fastResult.Upload)
}

Test

go test -v

Benchmark

go test -bench=.

LICENSE

MIT