http

package
Version: v1.2.7 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2021 License: Apache-2.0, MIT Imports: 16 Imported by: 7

Documentation

Overview

Package http provides a drand client implementation that uses drand's HTTP API.

The HTTP client uses drand's JSON HTTP API (https://drand.love/developer/http-api/) to fetch randomness. Watching is implemented by polling the endpoint at the expected round time.

Example:

package main

import (
	"encoding/hex"

	"github.com/drand/drand/client"
	"github.com/drand/drand/client/http"
)

var urls = []string{
	"https://api.drand.sh",
	"https://drand.cloudflare.com",
}

var chainHash, _ = hex.DecodeString("8990e7a9aaed2ffed73dbd7092123d6f289930540d7651336225dc172e51b2ce")

func main() {
	c, err := client.New(
		client.From(http.ForURLs(urls, chainHash)...),
		client.WithChainHash(chainHash),
	)
}

The "ForURLs" helper creates multiple HTTP clients from a list of URLs. Alternatively you can use the "New" or "NewWithInfo" constructor to create clients.

Tip: Provide multiple URLs to enable failover and speed optimized URL selection.

Index

Constants

View Source
const HTTPHeartbeatInterval = 10 * time.Second

HTTPHeartbeatInterval is the duration between liveness heartbeats sent to an HTTP API.

Variables

This section is empty.

Functions

func ForURLs

func ForURLs(urls []string, chainHash []byte) []client.Client

ForURLs provides a shortcut for creating a set of HTTP clients for a set of URLs.

func New

func New(url string, chainHash []byte, transport nhttp.RoundTripper) (client.Client, error)

New creates a new client pointing to an HTTP endpoint

func NewWithInfo

func NewWithInfo(url string, info *chain.Info, transport nhttp.RoundTripper) (client.Client, error)

NewWithInfo constructs an http client when the group parameters are already known.

Types

type HealthMetrics

type HealthMetrics struct {
	// contains filtered or unexported fields
}

HealthMetrics is a measurement task around HTTP clients

func MeasureHeartbeats

func MeasureHeartbeats(ctx context.Context, c []client.Client) *HealthMetrics

MeasureHeartbeats periodically tracks latency observed on a set of HTTP clients

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto