mlablocatev2

package
v3.12.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2021 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package mlablocatev2 implements m-lab locate services API v2. This API currently only allows you to get servers for ndt7. Use the mlablocate package for all other m-lab tools.

Example (Usage)
package main

import (
	"context"
	"fmt"
	"net/http"

	"github.com/apex/log"
	"github.com/ooni/probe-cli/v3/internal/mlablocatev2"
)

func main() {
	clnt := mlablocatev2.NewClient(http.DefaultClient, log.Log, "miniooni/0.1.0-dev")
	results, err := clnt.QueryNDT7(context.Background())
	if err != nil {
		log.WithError(err).Fatal("clnt.QueryNDT7 failed")
	}
	fmt.Printf("%+v\n", results)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrRequestFailed indicates that the response is not "200 Ok"
	ErrRequestFailed = errors.New("mlablocatev2: request failed")

	// ErrEmptyResponse indicates that no hosts were returned
	ErrEmptyResponse = errors.New("mlablocatev2: empty response")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// HTTPClient is the MANDATORY http client to use
	HTTPClient HTTPClient

	// Hostname is the MANDATORY hostname of the mlablocate API.
	Hostname string

	// Logger is the MANDATORY logger to use.
	Logger Logger

	// Scheme is the MANDATORY scheme to use (http or https).
	Scheme string

	// UserAgent is the MANDATORY user-agent to use.
	UserAgent string
}

Client is a client for v2 of the locate services. Please use the NewClient factory to construct a new instance of client, otherwise you MUST fill all the fields marked as MANDATORY.

func NewClient

func NewClient(httpClient HTTPClient, logger Logger, userAgent string) Client

NewClient creates a client for v2 of the locate services.

func (Client) QueryNDT7

func (c Client) QueryNDT7(ctx context.Context) ([]NDT7Result, error)

QueryNDT7 performs a v2 locate services query for ndt7.

type HTTPClient

type HTTPClient interface {
	// Do behaves like http.Client.Do.
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient is anything that looks like an http.Client.

type Logger

type Logger interface {
	// Debugf formats and emits a debug message.
	Debugf(format string, v ...interface{})
}

Logger is the logger expected by this package.

type NDT7Result

type NDT7Result struct {
	// Hostname is an informative field containing the hostname
	// to which you're connected. Because there are access tokens,
	// you cannot use this field directly.
	Hostname string

	// Site is an informative field containing the site
	// to which the server belongs to.
	Site string

	// WSSDownloadURL is the WebSocket URL to be used for
	// performing a download over HTTPS. Note that the URL
	// typically includes the required access token.
	WSSDownloadURL string

	// WSSUploadURL is like WSSDownloadURL but for the upload.
	WSSUploadURL string
}

NDT7Result is the result of a v2 locate services query for ndt7.

Jump to

Keyboard shortcuts

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