Back to godoc.org

Package http

v1.2.1
Latest Go to latest

The highest tagged major version is .

Published: 5 days ago | Licenses: Apache-2.0 , MIT | Module: github.com/drand/drand

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

const HTTPHeartbeatInterval = 10 * time.Second

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

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.

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

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier