ndt7 package - github.com/m-lab/ndt7-client-go - Go Packages

ndt7

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2019 License: Apache-2.0 Imports: 12 Imported by: 6

README

GoDoc Build Status Coverage Status Go Report Card

ndt7 Go client

Reference ndt7 Go client implementation. Useful resources:

The master branch contains stable code. We don't promise we won't break the API, but we'll try not to.

Installing

You need Go >= 1.12. We use modules. Make sure Go knows that:

export GO111MODULE=on

Clone the repository wherever you want with

git clone https://github.com/m-lab/ndt7-client-go

From inside the repository, use go get ./cmd/ndt7-client to build the client. Binaries will be placed in $GOPATH/bin, if GOPATH is set, and in $HOME/go/bin otherwise.

If you're into a one-off install, this

go get -v github.com/m-lab/ndt7-client-go/cmd/ndt7-client

is equivalent to cloning the repository, running go get ./cmd/ndt7-client, and then cancelling the repository directory.

Documentation

Overview

Package ndt7 contains a ndt7 client.

The client will automatically discover a suitable server to use by default. However, you can also manually discover a server and configure the client accordingly.

The code configures reasonable I/O timeouts. We recommend to also provide contexts with whole-operation timeouts attached, as we do in the code example provided as part of this package.

Example

This shows how to run a ndt7 test.

package main

import (
	"context"
	"log"
	"time"

	"github.com/m-lab/ndt7-client-go"
)

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
	defer cancel()
	client := ndt7.NewClient("ndt7-client-go-example", "0.1.0")
	ch, err := client.StartDownload(ctx)
	if err != nil {
		log.Fatal(err)
	}
	for ev := range ch {
		log.Printf("%+v", ev)
	}
	ch, err = client.StartUpload(ctx)
	if err != nil {
		log.Fatal(err)
	}
	for ev := range ch {
		log.Printf("%+v", ev)
	}
}

Index

Examples

Constants

View Source
const DefaultWebSocketHandshakeTimeout = 7 * time.Second

DefaultWebSocketHandshakeTimeout is the default timeout configured by NewClient in the Client.Dialer.HandshakeTimeout field.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// ClientName is the name of the software running ndt7 tests. It's set by
	// NewClient; you may want to change this value.
	ClientName string

	// ClientVersion is the version of the software running ndt7 tests. It's
	// set by NewClient; you may want to change this value.
	ClientVersion string

	// Dialer is the optional websocket Dialer. It's set to its
	// default value by NewClient; you may override it.
	Dialer websocket.Dialer

	// FQDN is the optional server FQDN. We will discover the FQDN of
	// a nearby M-Lab server for you if this field is empty.
	FQDN string

	// MLabNSClient is the mlabns client. We'll configure it with
	// defaults in NewClient and you may override it.
	MLabNSClient *mlabns.Client

	// Scheme is the scheme to use. It's set to "wss" by NewClient,
	// change it to "ws" for unencrypted ndt7.
	Scheme string
	// contains filtered or unexported fields
}

Client is a ndt7 client.

func NewClient

func NewClient(clientName, clientVersion string) *Client

NewClient creates a new client instance identified by the specified clientName and clientVersion. M-Lab services may reject requests coming from clients that do not identify themselves properly.

func (*Client) StartDownload

func (c *Client) StartDownload(ctx context.Context) (<-chan spec.Measurement, error)

StartDownload discovers a ndt7 server (if needed) and starts a download. On success it returns a channel where measurements are emitted. This channel is closed when the download ends. On failure, the error is non nil and you should not attempt using the channel. A side effect of starting the download is that, if you did not specify a server FQDN, we will discover a server for you and store that value into the c.FQDN field.

func (*Client) StartUpload

func (c *Client) StartUpload(ctx context.Context) (<-chan spec.Measurement, error)

StartUpload is like StartDownload but for the upload.

Directories

Path Synopsis
cmd
ndt7-client command
ndt7-client is the ndt7 command line client.
ndt7-client is the ndt7 command line client.
ndt7-client/internal/emitter
Package emitter contains the ndt7-client emitter.
Package emitter contains the ndt7-client emitter.
ndt7-client/internal/mocks
Package mocks contains mocks
Package mocks contains mocks
internal
download
Package download contains ndt7 download code.
Package download contains ndt7 download code.
mocks
Package mocks implements mocks.
Package mocks implements mocks.
params
Package params contains private constants and structs.
Package params contains private constants and structs.
upload
Package upload contains ndt7 upload code
Package upload contains ndt7 upload code
websocketx
Package websocketx contains websocket extensions.
Package websocketx contains websocket extensions.
Package mlabns implements a simple mlab-ns client.
Package mlabns implements a simple mlab-ns client.
Package spec contains constants and structs.
Package spec contains constants and structs.

Jump to

Keyboard shortcuts

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