Documentation ¶
Index ¶
- Constants
- Variables
- func ConvertData(ctx context.Context, src, dst api.Protocol, srcData buffer.IoBuffer) (buffer.IoBuffer, error)
- func ConvertHeader(ctx context.Context, src, dst api.Protocol, srcHeader api.HeaderMap) (api.HeaderMap, error)
- func ConvertTrailer(ctx context.Context, src, dst api.Protocol, srcTrailer api.HeaderMap) (api.HeaderMap, error)
- func GenerateID() uint64
- func GenerateIDString() string
- func MappingHeaderStatusCode(ctx context.Context, p api.Protocol, headers api.HeaderMap) (int, error)
- func RegisterCommonConv(protocol api.Protocol, from, to ProtocolConv)
- func RegisterConv(src, dst api.Protocol, f ProtocolConv)
- func RegisterMapping(p api.Protocol, m HTTPMapping)
- func RequestIDConv(streamID string) uint64
- func StreamIDConv(streamID uint64) string
- type CommonHeader
- func (h CommonHeader) Add(key string, value string)
- func (h CommonHeader) ByteSize() uint64
- func (h CommonHeader) Clone() api.HeaderMap
- func (h CommonHeader) Del(key string)
- func (h CommonHeader) Get(key string) (value string, ok bool)
- func (h CommonHeader) Range(f func(key, value string) bool)
- func (h CommonHeader) Set(key string, value string)
- type HTTPMapping
- type IDGenerator
- type ProtocolBuffers
- func (p *ProtocolBuffers) GetReqData(size int) buffer.IoBuffer
- func (p *ProtocolBuffers) GetReqHeader(size int) buffer.IoBuffer
- func (p *ProtocolBuffers) GetReqHeaders() map[string]string
- func (p *ProtocolBuffers) GetReqTailers() map[string]string
- func (p *ProtocolBuffers) GetRspData(size int) buffer.IoBuffer
- func (p *ProtocolBuffers) GetRspHeader(size int) buffer.IoBuffer
- func (p *ProtocolBuffers) GetRspHeaders() map[string]string
- func (p *ProtocolBuffers) GetRspTailers() map[string]string
- type ProtocolConv
Constants ¶
const ( Auto api.Protocol = "Auto" SofaRPC api.Protocol = "SofaRpc" HTTP1 api.Protocol = "Http1" HTTP2 api.Protocol = "Http2" Xprotocol api.Protocol = "X" )
ProtocolName type definition
const ( Request = "Request" Response = "Response" )
header direction definition
Variables ¶
var ( ErrNotFound = errors.New("no convert function found for given protocol pair") ErrHeaderDirection = errors.New("no header direction info") )
var (
ErrNoMapping = errors.New("no mapping function found")
)
Functions ¶
func ConvertData ¶
func ConvertData(ctx context.Context, src, dst api.Protocol, srcData buffer.IoBuffer) (buffer.IoBuffer, error)
ConvertData convert data from source protocol format to destination protocol format
func ConvertHeader ¶
func ConvertHeader(ctx context.Context, src, dst api.Protocol, srcHeader api.HeaderMap) (api.HeaderMap, error)
ConvertHeader convert header from source protocol format to destination protocol format
func ConvertTrailer ¶
func ConvertTrailer(ctx context.Context, src, dst api.Protocol, srcTrailer api.HeaderMap) (api.HeaderMap, error)
ConvertTrailer convert trailer from source protocol format to destination protocol format
func GenerateIDString ¶
func GenerateIDString() string
GenerateIDString get id string by default global generator
func MappingHeaderStatusCode ¶
func RegisterCommonConv ¶
func RegisterCommonConv(protocol api.Protocol, from, to ProtocolConv)
RegisterCommonConv register concrete protocol convert function for specified protocol and common representation. e.g. SofaRpcCmd <-> CommonHeader, which both implements the types.HeaderMap interface
func RegisterConv ¶
func RegisterConv(src, dst api.Protocol, f ProtocolConv)
RegisterConv register concrete protocol convert function for specified source protocol and destination protocol
func RegisterMapping ¶
func RegisterMapping(p api.Protocol, m HTTPMapping)
func RequestIDConv ¶
RequestIDConv convert streamID from string to uint64
func StreamIDConv ¶
StreamIDConv convert streamID from uint64 to string
Types ¶
type CommonHeader ¶
CommonHeader wrapper for map[string]string
func (CommonHeader) Add ¶
func (h CommonHeader) Add(key string, value string)
Add value for given key. Multiple headers with the same key may be added with this function. Use Set for setting a single header for the given key.
func (CommonHeader) ByteSize ¶
func (h CommonHeader) ByteSize() uint64
func (CommonHeader) Clone ¶
func (h CommonHeader) Clone() api.HeaderMap
Clone used to deep copy header's map
func (CommonHeader) Get ¶
func (h CommonHeader) Get(key string) (value string, ok bool)
Get value of key
func (CommonHeader) Range ¶
func (h CommonHeader) Range(f func(key, value string) bool)
Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.
func (CommonHeader) Set ¶
func (h CommonHeader) Set(key string, value string)
Set key-value pair in header map, the previous pair will be replaced if exists
type HTTPMapping ¶
type HTTPMapping interface {
MappingHeaderStatusCode(ctx context.Context, headers api.HeaderMap) (int, error)
}
HTTPMapping maps the contents of protocols to HTTP standard
type IDGenerator ¶
type IDGenerator struct {
// contains filtered or unexported fields
}
IDGenerator utility to generate auto-increment ids
func (*IDGenerator) GetString ¶
func (g *IDGenerator) GetString() string
Get get id in string format
type ProtocolBuffers ¶
type ProtocolBuffers struct {
// contains filtered or unexported fields
}
func ProtocolBuffersByContext ¶
func ProtocolBuffersByContext(ctx context.Context) *ProtocolBuffers
ProtocolBuffersByContext returns ProtocolBuffers by context
func (*ProtocolBuffers) GetReqData ¶
func (p *ProtocolBuffers) GetReqData(size int) buffer.IoBuffer
GetReqData returns IoBuffer for request data
func (*ProtocolBuffers) GetReqHeader ¶
func (p *ProtocolBuffers) GetReqHeader(size int) buffer.IoBuffer
GetReqHeader returns IoBuffer for request header
func (*ProtocolBuffers) GetReqHeaders ¶
func (p *ProtocolBuffers) GetReqHeaders() map[string]string
GetReqHeaders returns map for request header
func (*ProtocolBuffers) GetReqTailers ¶
func (p *ProtocolBuffers) GetReqTailers() map[string]string
GetReqTailers returns map for request tailers
func (*ProtocolBuffers) GetRspData ¶
func (p *ProtocolBuffers) GetRspData(size int) buffer.IoBuffer
GetRspData returns IoBuffer for response data
func (*ProtocolBuffers) GetRspHeader ¶
func (p *ProtocolBuffers) GetRspHeader(size int) buffer.IoBuffer
GetRspHeader returns IoBuffer for response header
func (*ProtocolBuffers) GetRspHeaders ¶
func (p *ProtocolBuffers) GetRspHeaders() map[string]string
GetRspHeaders returns map for response header
func (*ProtocolBuffers) GetRspTailers ¶
func (p *ProtocolBuffers) GetRspTailers() map[string]string
GetRspTailers returns IoBuffer for response tailers
type ProtocolConv ¶
type ProtocolConv interface { // ConvHeader convert header part represents in `api.HeaderMap` ConvHeader(ctx context.Context, headerMap api.HeaderMap) (api.HeaderMap, error) // ConvData convert data part represents in `buffer.IoBuffer` ConvData(ctx context.Context, buffer buffer.IoBuffer) (buffer.IoBuffer, error) // ConvTrailer convert trailer part represents in `api.HeaderMap` ConvTrailer(ctx context.Context, headerMap api.HeaderMap) (api.HeaderMap, error) }
ProtocolConv extract common methods for protocol conversion(header, data, trailer)