fossilizerhttp

package
v0.0.4-dev Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2016 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package fossilizerhttp is used to create an HTTP server from a fossilizer adapter.

It serves the following routes:

GET /
	Renders information about the fossilizer.

POST /fossils
	Requests data to be fossilized.
	Form.data should be a hex encoded buffer.
	Form.callbackUrl should be a URL to be called when the evidence
	is ready.
Example

This example shows how to create a server from a dummyfossilizer. It also tests the root route of the server using net/http/httptest.

package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"net/http/httptest"

	"github.com/stratumn/go/dummyfossilizer"
	"github.com/stratumn/go/fossilizer/fossilizerhttp"
	"github.com/stratumn/go/jsonhttp"
)

func main() {
	// Create a dummy adapter.
	a := dummyfossilizer.New(&dummyfossilizer.Config{Version: "0.1.0", Commit: "abc"})
	config := &fossilizerhttp.Config{
		MaxDataLen: 64,
	}
	httpConfig := &jsonhttp.Config{
		Address: ":6000",
	}

	// Create a server.
	s := fossilizerhttp.New(a, config, httpConfig)

	// Create a test server.
	ts := httptest.NewServer(s)
	defer ts.Close()

	// Test the root route.
	res, err := http.Get(ts.URL)
	if err != nil {
		log.Fatal(err)
	}

	info, err := ioutil.ReadAll(res.Body)
	res.Body.Close()
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("%s", info)
}
Output:

{"adapter":{"name":"dummy","description":"Stratumn Dummy Fossilizer","version":"0.1.0","commit":"abc"}}

Index

Examples

Constants

View Source
const (
	// DefaultAddress is the default address of the server.
	DefaultAddress = ":6000"

	// DefaultNumResultWorkers is the default number of goroutines that will
	// be used to handle fossilizer results.
	DefaultNumResultWorkers = 8

	// DefaultMinDataLen is the default minimum fossilize data length.
	DefaultMinDataLen = 32

	// DefaultMaxDataLen is the default maximum fossilize data length.
	DefaultMaxDataLen = 64

	// DefaultCallbackTimeout is the default timeout of requests to the
	// callback URLs.
	DefaultCallbackTimeout = 10 * time.Second
)

Variables

This section is empty.

Functions

func New

func New(a fossilizer.Adapter, config *Config, httpConfig *jsonhttp.Config) *jsonhttp.Server

New create an instance of a server.

Types

type Config

type Config struct {
	// The default number of goroutines that will be used to handle
	// fossilizer results.
	NumResultWorkers int

	// The minimum fossilize data length.
	MinDataLen int

	// The maximum fossilize data length.
	MaxDataLen int

	// The timeout of requests to the callback URLs.
	CallbackTimeout time.Duration
}

Config contains configuration options for the server.

type Info

type Info struct {
	Adapter interface{} `json:"adapter"`
}

Info is the info returned by the root route.

Jump to

Keyboard shortcuts

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