Documentation ¶
Index ¶
- Variables
- func DecodeHeader(bytes []byte, h *Header) (err error)
- func EncodeHeader(buf types.IoBuffer, h *Header)
- func GetHeaderEncodeLength(h *Header) (size int)
- func GetMapping(name types.ProtocolName) protocol.HTTPMapping
- func GetMatcher(name types.ProtocolName) types.ProtocolMatch
- func GetMatchers() map[types.ProtocolName]types.ProtocolMatch
- func RegisterMapping(name types.ProtocolName, mapping protocol.HTTPMapping) error
- func RegisterMatcher(name types.ProtocolName, matcher types.ProtocolMatch) error
- func RegisterProtocol(name types.ProtocolName, protocol XProtocol) error
- type BytesKV
- type GoAwayPredicate
- type Header
- func (h *Header) Add(Key string, Value string)
- func (h *Header) ByteSize() (size uint64)
- func (h *Header) Clone() *Header
- func (h *Header) Del(Key string)
- func (h *Header) Get(Key string) (Value string, ok bool)
- func (h *Header) Range(f func(Key, Value string) bool)
- func (h *Header) Set(Key string, Value string)
- type HeartbeatPredicate
- type Heartbeater
- type Hijacker
- type Multiplexing
- type ServiceAware
- type StreamType
- type XEngine
- type XFrame
- type XProtocol
- type XRespFrame
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoSubProtocolFound = errors.New("no sub protocol found in context") ErrNoDelegateFound = errors.New("no sub protocol delegate function found") )
var ( AlreadyRegistered = "protocol code already registered" UnknownType = "unknown model type" UnrecognizedCode = "unrecognized protocol code" NoProtocolCode = "no protocol code found" ErrDupRegistered = errors.New(AlreadyRegistered) ErrUnknownType = errors.New(UnknownType) ErrUnrecognizedCode = errors.New(UnrecognizedCode) ErrNoProtocolCode = errors.New(NoProtocolCode) )
Error def
Functions ¶
func DecodeHeader ¶
func EncodeHeader ¶
func GetHeaderEncodeLength ¶
func GetMapping ¶ added in v0.12.0
func GetMapping(name types.ProtocolName) protocol.HTTPMapping
GetMapping return the corresponding HTTP status code mapping function for given name(if was registered)
func GetMatcher ¶
func GetMatcher(name types.ProtocolName) types.ProtocolMatch
GetMatcher return the corresponding matcher for given name(if was registered)
func GetMatchers ¶ added in v0.20.0
func GetMatchers() map[types.ProtocolName]types.ProtocolMatch
GetMatchers return all matchers that was registered
func RegisterMapping ¶ added in v0.12.0
func RegisterMapping(name types.ProtocolName, mapping protocol.HTTPMapping) error
RegisterMapping register the HTTP status code mapping function of the protocol into factory
func RegisterMatcher ¶
func RegisterMatcher(name types.ProtocolName, matcher types.ProtocolMatch) error
RegisterMatcher register the matcher of the protocol into factory
func RegisterProtocol ¶
func RegisterProtocol(name types.ProtocolName, protocol XProtocol) error
RegisterProtocol register the protocol to factory
Types ¶
type GoAwayPredicate ¶
type GoAwayPredicate interface {
IsGoAwayFrame() bool
}
HeartbeatPredicate provides the ability to judge if current is a goaway frmae, which indicates that current connection should be no longer used and turn into the draining state.
type Header ¶
Header consists of multi key-value pair in byte slice formation. This could reduce the cost of []byte to string for protocol codec.
type HeartbeatPredicate ¶
type HeartbeatPredicate interface {
IsHeartbeatFrame() bool
}
HeartbeatPredicate provides the ability to judge if current frame is a heartbeat, which is usually used to make connection keepalive
type Heartbeater ¶
type Heartbeater interface { // Trigger builds an active heartbeat command Trigger(requestId uint64) XFrame // Reply builds heartbeat command corresponding to the given requestID Reply(request XFrame) XRespFrame }
HeartbeatBuilder provides the ability to construct proper heartbeat command for xprotocol sub-protocols
type Hijacker ¶
type Hijacker interface { // BuildResponse build response with given status code Hijack(request XFrame, statusCode uint32) XRespFrame // Mapping the http status code, which used by proxy framework into protocol-specific status Mapping(httpStatusCode uint32) uint32 }
Hijacker provides the ability to construct proper response command for xprotocol sub-protocols
type Multiplexing ¶
Multiplexing provides the ability to distinguish multi-requests in single-connection by recognize 'request-id' semantics
type ServiceAware ¶
ServiceAware provides the ability to get the most common info for rpc invocation: service name and method name
type StreamType ¶
type StreamType int
StreamType distinguish the stream flow type. Request: stream is a normal request and needs response RequestOneWay: stream is a oneway request and doesn't need response Response: stream is a response to specific request
const ( Request StreamType = iota RequestOneWay Response )
type XEngine ¶
type XEngine struct {
// contains filtered or unexported fields
}
XEngine is an implementation of the ProtocolEngine interface
func NewXEngine ¶
type XFrame ¶
type XFrame interface { // TODO: make multiplexing optional, and maybe we can support PING-PONG protocol in this framework. Multiplexing HeartbeatPredicate GetStreamType() StreamType GetHeader() types.HeaderMap GetData() types.IoBuffer SetData(data types.IoBuffer) }
XFrame represents the minimal programmable object of the protocol.
type XProtocol ¶
type XProtocol interface { types.Protocol Heartbeater Hijacker PoolMode() types.PoolMode // configure this to use which connpool EnableWorkerPool() bool // same meaning as EnableWorkerPool in types.StreamConnection // generate a request id for stream to combine stream request && response // use connection param as base GenerateRequestID(*uint64) uint64 }
XProtocol provides extra ability(Heartbeater, Hijacker) to interacts with the proxy framework based on the Protocol interface. e.g. A request which cannot find route should be responded with a error response like '404 Not Found', that is what Hijacker interface exactly provides.
func GetProtocol ¶
func GetProtocol(name types.ProtocolName) XProtocol
GetProtocol return the corresponding protocol for given name(if was registered)
type XRespFrame ¶
XRespFrame expose response status code based on the XFrame