protocol

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2020 License: Apache-2.0 Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotImplementation   = errors.New("not implementation")
	ErrProtocolNotRegister = errors.New("protocol not register")
)

Functions

func RegisterMapInterfaceOptFunc

func RegisterMapInterfaceOptFunc(protocol string, withMapInterfaceOpt MapInterfaceOptFunc)

RegisterMapInterfaceOptFunc registers MapInterfaceOptFunc by protocol name.

func RegisterProtocol

func RegisterProtocol(protocol string, builder ClientBuilder)

RegisterProtocol registers pair <protocol, ClientBuilder> to defaultClientRegister.

Types

type Client

type Client interface {
	// GetResource gets resource by argument.
	GetResource(url string, md Metadata) Resource
}

Client defines how to get resource.

type ClientBuilder

type ClientBuilder interface {
	// NewProtocolClient creates an instance of Client.
	// Here have a suggestion that every implementation should have
	// opts with WithMapInterface(map[string]interface),
	// which may be easier for configuration with config file.
	NewProtocolClient(opts ...func(client Client) error) (Client, error)
}

ClientBuilder defines how to create an instance of Client.

func GetClientBuilder

func GetClientBuilder(protocol string) (ClientBuilder, error)

GetClientBuilder get ClientBuilder by protocol in defaultClientRegister.

type ClientRegister

type ClientRegister interface {
	// ClientRegister registers pair <protocol, ClientBuilder>.
	RegisterProtocol(protocol string, builder ClientBuilder)

	// GetClientBuilder gets the ClientBuilder by protocol.
	GetClientBuilder(protocol string) (ClientBuilder, error)
}

ClientRegister defines how to register pair <protocol, ClientBuilder>.

type DataEncoder

type DataEncoder interface {
	// Encode data.
	Encode(io.Reader) (io.Reader, error)

	// Decode data.
	Decode(io.Reader) (io.Reader, error)
}

DataEncoder defines how to encode/decode data.

type DataType

type DataType interface {
	// String return the type string.
	String() string

	// Encoder return the encoder of the type.
	Encoder() DataEncoder
}

DataType defines the type of DistributionData.

type DistributionData

type DistributionData interface {
	// Type gets the data type.
	Type() DataType

	// Size gets the size of data.
	Size() int64

	// Metadata gets the metadata.
	Metadata() interface{}

	// Content gets the content of data.
	Content(ctx context.Context) (io.Reader, error)
}

DistributionData defines the protocol of distribute data which is exchanged in peers.

func NewEoFDistributionData

func NewEoFDistributionData() DistributionData

type MapInterfaceOptFunc

type MapInterfaceOptFunc func(map[string]interface{}) func(Client) error

func GetRegisteredMapInterfaceOptFunc

func GetRegisteredMapInterfaceOptFunc(protocol string) (MapInterfaceOptFunc, error)

GetRegisteredMapInterfaceOptFunc get MapInterfaceOptFunc by protocol name.

type Metadata

type Metadata interface {
	Get(key string) (interface{}, error)
	Set(key string, value interface{})
	Del(key string)
	All() interface{}
}

Metadata defines how to operate the metadata.

type Resource

type Resource interface {
	// Read gets range data from the binding resource.
	Read(ctx context.Context, off int64, size int64) (io.ReadCloser, error)

	// Length gets the length of binding resource.
	Length(ctx context.Context) (int64, error)

	// Metadata gets the metadata of binding resource.
	Metadata(ctx context.Context) (Metadata, error)

	// Expire gets if the binding resource is expired.
	Expire(ctx context.Context) (bool, interface{}, error)

	// Call allows user defined request.
	Call(ctx context.Context, request interface{}) (response interface{}, err error)

	// Close the resource.
	io.Closer
}

Resource defines the way how to get some information from remote resource. An instance should bind a resource. Developers can implement their own Resource which could support different protocol.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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