rpcstore

package module
v0.0.0-...-0b3a9b5 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2023 License: BSD-3-Clause Imports: 5 Imported by: 3

README

rpcstore

GoDoc

Package rpcstore bridges the blob.Store interface over a JSON-RPC 2.0 interface.

Documentation

Overview

Package rpcstore implements the blob.Store that delegates to an underlying store via a JSON-RPC interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CAS

type CAS struct {
	Store
}

CAS implements the blob.CAS interface by calling a JSON-RPC service.

func NewCAS

func NewCAS(cli *jrpc2.Client, opts *StoreOpts) CAS

NewCAS constructs a CAS that delegates through the given client.

func (CAS) CASKey

func (c CAS) CASKey(ctx context.Context, opts blob.CASPutOptions) (string, error)

CASKey implements part of the blob.CAS type.

func (CAS) CASPut

func (c CAS) CASPut(ctx context.Context, opts blob.CASPutOptions) (string, error)

CASPut implements part of the blob.CAS type.

type CASPutRequest

type CASPutRequest struct {
	Data   []byte `json:"data"`
	Prefix []byte `json:"prefix,omitempty"`
	Suffix []byte `json:"suffix,omitempty"`
}

CASPutRequest is the request to the CASPut and CASGet methods.

type KeyRequest

type KeyRequest struct {
	Key []byte `json:"key"`
}

KeyRequest is the request to the Get, Delete, and Size methods.

type ListReply

type ListReply struct {
	Keys [][]byte `json:"keys"`
	Next []byte   `json:"next,omitempty"`
}

ListReply is the reply from the List method.

type ListRequest

type ListRequest struct {
	Start []byte `json:"start"`
	Count int    `json:"count"`
}

ListRequest is the request to the List method.

type PutRequest

type PutRequest struct {
	Key     []byte `json:"key"`
	Data    []byte `json:"data"`
	Replace bool   `json:"replace"`
}

PutRequest is the request to the Put method.

type Service

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

Service implements a service that adapts RPC requests to a blob.Store.

All service instances export the following methods:

Method    JSON Request and response messsages
"get"     {"key":"<storage-key"}
          "<blob-content>"

"put"     {"key":"<storage-key>","data":"<blob-content>","replace":bool}
          null

"size"    {"key":"<storage-key>"}
          <integer>

"len":    null
          <integer>

"list":   {"start":"<storage-key>","count":<integer>}
          {"keys":["<storage-key>",...],"next":"<storage-key>"}

If the store delegated to the service implements blob.CAS, the service will also export these additional methods:

"cas.put" {"data":"<blob-data>", "prefix":"...", "suffix":"..."}
          "<storage-key>"

"cas.key" {"data":"<blob-data>", "prefix":"...", "suffix":"..."}
          "<storage-key>"

The data formats are:

<storage-key>   : base-64 encoded string (key), example: "a2V5Zm9v"
<blob-content>  : base-64 encoded string (data), example: "ZGF0YWZvbw=="
<integer>       : JSON number with integer value, example: 532

func NewService

func NewService(st blob.Store, opts *ServiceOpts) *Service

NewService constructs a Service that delegates to the given blob.Store.

func (Service) CASKey

func (s Service) CASKey(ctx context.Context, req *CASPutRequest) ([]byte, error)

CASKey computes and returns the hash key for the specified data, if the service has a hash constructor installed.

func (Service) CASPut

func (s Service) CASPut(ctx context.Context, req *CASPutRequest) ([]byte, error)

CASPut implements content-addressable storage if the service has a hash constructor installed.

func (Service) Delete

func (s Service) Delete(ctx context.Context, req *KeyRequest) error

Delete handles the corresponding method of blob.Store.

func (Service) Get

func (s Service) Get(ctx context.Context, req *KeyRequest) ([]byte, error)

Get handles the corresponding method of blob.Store.

func (Service) Len

func (s Service) Len(ctx context.Context) (int64, error)

Len handles the corresponding method of blob.Store.

func (Service) List

func (s Service) List(ctx context.Context, req *ListRequest) (*ListReply, error)

List handles the corresponding method of blob.Store.

func (Service) Methods

func (s Service) Methods() jrpc2.Assigner

Methods returns a map of the service methods for s.

func (Service) Put

func (s Service) Put(ctx context.Context, req *PutRequest) error

Put handles the corresponding method of blob.Store.

type ServiceOpts

type ServiceOpts struct{}

ServiceOpts provides optional settings for constructing a Service.

type Store

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

Store implements the blob.Store interface by calling a JSON-RPC service.

func NewStore

func NewStore(cli *jrpc2.Client, opts *StoreOpts) Store

NewStore constructs a Store that delegates through the given client.

func (Store) Close

func (s Store) Close(_ context.Context) error

Close implements a method of blob.Store.

func (Store) Delete

func (s Store) Delete(ctx context.Context, key string) error

Delete implements a method of blob.Store.

func (Store) Get

func (s Store) Get(ctx context.Context, key string) ([]byte, error)

Get implements a method of blob.Store.

func (Store) Len

func (s Store) Len(ctx context.Context) (int64, error)

Len implements a method of blob.Store.

func (Store) List

func (s Store) List(ctx context.Context, start string, f func(string) error) error

List implements a method of blob.Store.

func (Store) Put

func (s Store) Put(ctx context.Context, opts blob.PutOptions) error

Put implements a method of blob.Store.

func (Store) ServerInfo

func (s Store) ServerInfo(ctx context.Context) (*jrpc2.ServerInfo, error)

ServerInfo returns the JSON-RPC server status message.

type StoreOpts

type StoreOpts struct {
	// Insert this prefix on all method names sent to the service.
	Prefix string
}

StoreOpts provide optional settings for a Store client

Jump to

Keyboard shortcuts

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