Documentation
¶
Index ¶
- Variables
- func RegisterMapInterfaceOptFunc(protocol string, withMapInterfaceOpt MapInterfaceOptFunc)
- func RegisterProtocol(protocol string, builder ClientBuilder)
- type Client
- type ClientBuilder
- type ClientRegister
- type DataEncoder
- type DataType
- type DistributionData
- type MapInterfaceOptFunc
- type Metadata
- type Resource
Constants ¶
This section is empty.
Variables ¶
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 ¶
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.