nw

package
v0.0.0-...-917641f Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Example
store := ops.Polled(testops.MemStore(nil))
defer store.Close()
handler := &nw.Handler{Store: store}
srv := httptest.NewServer(handler)
defer srv.Close()

c := nw.Client{URL: srv.URL, Client: srv.Client()}
defer c.Close()

op1 := ops.Operation{OpID: "ID1", ParentID: "", VerID: 100, BasisID: -1}
op2 := ops.Operation{OpID: "ID2", ParentID: "ID1", VerID: 100, BasisID: -1, Change: changes.ChangeSet{changes.Move{Offset: 1, Count: 2, Distance: 3}}}

ctx := getContext()
if err := c.Append(ctx, []ops.Op{op1}); err != nil {
	fmt.Println("Append1", err)
	return
}
if err := c.Append(ctx, []ops.Op{op2}); err != nil {
	fmt.Println("Append2", err)
	return
}

ops, err := c.GetSince(ctx, 0, 100)
fmt.Println("Ops", ops, err)
Output:

Ops [{ID1  0 -1 <nil>} {ID2 ID1 1 -1 [{1 2 3}]}] <nil>

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultCodecs = map[string]Codec{
	"application/x-gob":   gobCodec{},
	"application/x-sjson": sjson.Std,
}

DefaultCodecs is the default codecs list which contains a map of content-type to codec.

Functions

func Register

func Register(v interface{})

Register registers the values with all the default codecs

Types

type Client

type Client struct {
	URL         string
	Header      map[string]string
	ContentType string
	Codecs      map[string]Codec
	log.Log

	*http.Client
}

Client implements the ops.Store interface by making network calls to the provided Url. All other fields of the Client are optional.

func (*Client) Append

func (c *Client) Append(ctx context.Context, o []ops.Op) error

Append proxies the Append call over to the url

func (*Client) Close

func (c *Client) Close()

Close proxies the Close call over to the url

func (*Client) GetSince

func (c *Client) GetSince(ctx context.Context, version, limit int) ([]ops.Op, error)

GetSince proxies the GetSince call over to the url

type Codec

type Codec interface {
	Encode(value interface{}, writer io.Writer) error
	Decode(value interface{}, reader io.Reader) error
	Register(v interface{})
}

Codec is the interface codecs will have to implement to marshal and unmarshal requests and responses

type Handler

type Handler struct {
	ops.Store
	Codecs map[string]Codec
	log.Log
	// contains filtered or unexported fields
}

Handler implements ServerHTTP using the provided store and codecs map. If no codecs map is provided, DefaultCodecs is used instead.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP uses the code to unmarshal a request, apply it and then encode back the response

Jump to

Keyboard shortcuts

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