mlablocate

package
v3.14.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2022 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package mlablocate contains a locate.measurementlab.net client implementing v1 of the locate API. This version of the API isn't suitable for requesting servers for ndt7. You should use the mlablocatev2 package for that.

Example (Usage)
package main

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

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

func main() {
	clnt := mlablocate.NewClient(http.DefaultClient, log.Log, "miniooni/0.1.0-dev")
	result, err := clnt.Query(context.Background(), "neubot/dash")
	if err != nil {
		log.WithError(err).Fatal("clnt.Query failed")
	}
	fmt.Printf("%s\n", result.FQDN)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

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

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

	// 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 locate.measurementlab.net client. 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 model.HTTPClient, logger model.DebugLogger, userAgent string) *Client

NewClient creates a new locate.measurementlab.net client.

func (*Client) Query

func (c *Client) Query(ctx context.Context, tool string) (Result, error)

Query performs a locate.measurementlab.net query. This function returns either valid result, on success, or an error, on failure. (Note thay you cannot use this API to query for ndt7 servers. You should use the mlablocatev2 API to obtain such servers.)

type Result

type Result struct {
	// FQDN is the mlab server's FQDN.
	FQDN string `json:"fqdn"`

	// Site is the ID of the site where the server is.
	Site string `json:"site"`
}

Result is a result of a query to locate.measurementlab.net.

Jump to

Keyboard shortcuts

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