storehttp

package
v0.0.3-dev Latest Latest
Warning

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

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

Documentation

Overview

Package storehttp is used to create an HTTP server from a store adapter.

It serves the following routes:

GET /
	Renders information about the fossilizer.

POST /segments
	Saves then renders a segment.
	Body should be a JSON encoded segment.

GET /segments/:linkHash
	Renders a segment.

DELETE /segments/:linkHash
	Deletes then renders a segment.

GET /segments?[offset=offset]&[limit=limit]&[mapId=mapId]&[prevLinkHash=prevLinkHash]&[tags=list+of+tags]
	Finds and renders segments.

GET /maps?[offset=offset]&[limit=limit]
	Finds and renders map IDs.
Example

This example shows how to create a server from a dummystore. 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/dummystore"
	"github.com/stratumn/go/jsonhttp"
	"github.com/stratumn/go/store/storehttp"
)

func main() {
	// Create a dummy adapter.
	a := dummystore.New(&dummystore.Config{Version: "0.1.0", Commit: "abc"})
	c := &jsonhttp.Config{
		Address: "5555",
	}

	// Create a server.
	s := storehttp.New(a, c)

	// 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 Store","version":"0.1.0","commit":"abc"}}

Index

Examples

Constants

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

Variables

This section is empty.

Functions

func New

New create an instance of a server.

Types

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