Documentation
¶
Index ¶
- Constants
- Variables
- func CloneContext(ctx context.Context) context.Context
- func CopyMsg(dst, src *Msg)
- func RecycleMessage(msg *Msg)
- type EncryptFrameHead
- type FrameHead
- type Msg
- func (m *Msg) CallRPCName() string
- func (m *Msg) CalleeMethod() string
- func (m *Msg) CalleeServiceName() string
- func (m *Msg) CallerMethod() string
- func (m *Msg) CallerServiceName() string
- func (m *Msg) ClientReqHead() interface{}
- func (m *Msg) ClientRespError() error
- func (m *Msg) ClientRespHead() interface{}
- func (m *Msg) Context() context.Context
- func (m *Msg) Env() string
- func (m *Msg) FrameCodec() interface{}
- func (m *Msg) LocalAddr() net.Addr
- func (m *Msg) LogSeq() int
- func (m *Msg) Logger() logger.Logger
- func (m *Msg) RemoteAddr() net.Addr
- func (m *Msg) RequestID() uint64
- func (m *Msg) RequestTimeout() time.Duration
- func (m *Msg) SerializationType() int
- func (m *Msg) ServerReqHead() interface{}
- func (m *Msg) ServerRespError() *errs.Error
- func (m *Msg) ServerRespHead() interface{}
- func (m *Msg) SpanID() uint64
- func (m *Msg) TraceID() string
- func (m *Msg) WithCallRPCName(s string)
- func (m *Msg) WithCalleeMethod(s string)
- func (m *Msg) WithCalleeServiceName(s string)
- func (m *Msg) WithCallerMethod(s string)
- func (m *Msg) WithCallerServiceName(s string)
- func (m *Msg) WithClientReqHead(h interface{})
- func (m *Msg) WithClientRespError(e error)
- func (m *Msg) WithClientRespHead(h interface{})
- func (m *Msg) WithEnv(env string)
- func (m *Msg) WithFrameCodec(f interface{})
- func (m *Msg) WithLocalAddr(addr net.Addr)
- func (m *Msg) WithLogger(l logger.Logger)
- func (m *Msg) WithRemoteAddr(addr net.Addr)
- func (m *Msg) WithRequestID(id uint64)
- func (m *Msg) WithRequestTimeout(t time.Duration)
- func (m *Msg) WithSerializationType(t int)
- func (m *Msg) WithServerReqHead(h interface{})
- func (m *Msg) WithServerRespError(e error)
- func (m *Msg) WithServerRespHead(h interface{})
- func (m *Msg) WithSpanID(id uint64)
- func (m *Msg) WithTraceID(id string)
- type SignFrameHead
Constants ¶
const ( // FrameTypeNormal mainly used in a secure environment, such as a private LAN. FrameTypeNormal = 0 FrameHeadLen = 10 // total length of frame head ProtocolVersion = 1 // protocol version v1 // FrameTypeSignature mainly used for intercommunication between // data in the same cloud through the bastion host. FrameTypeSignature = 1 // signature frame SignFrameHeadLen = 43 // total length of sign frame head SignVersion = 1 // version of signature frame // FrameTypeEncrypt mainly used for android, iphone and // other terminal devices to directly access workspace data, // to prevent data from being hijacked. FrameTypeEncrypt = 2 // encrypt frame EncryptFrameHeadLen = 11 // total length of sign frame head EncryptVersion = 1 // version of encrypt frame ProtocolTypeRPC = 1 // protocol type rpc ProtocolTypeHTTP = 2 // protocol type http )
const ContextMsg = "CTX_MSG"
Variables ¶
var ( ErrHeadOverflowsUint16 = errors.New("head len overflows uint16") ErrHeadOverflowsUint32 = errors.New("total len overflows uint32") ErrFrameTooLarge = errors.New("length of frame is larger than MaxFrameSize") )
var (
MaxFrameSize = 10 * 1024 * 1024 // max size of frame.
)
Functions ¶
func CloneContext ¶
CloneContext copies the context and gets a context that retains the value and does not cancel, which is used for asynchronous processing by handler, leaving the original timeout control and retains the original context information.
After the rpc handler function returns, ctx will be canceled, and put the ctx's Msg back into pool, and the associated Metrics and log will be released.
When the handler function runs asynchronously, this method needs to be called before starting goroutine to copy the context, leaving the original timeout control, and retains the information in Msg for Metrics.
Retain the log context for printing the associated log, keep other value in context, such as tracing context, etc.
func RecycleMessage ¶
func RecycleMessage(msg *Msg)
RecycleMessage reset message, then put it to pool.
Types ¶
type EncryptFrameHead ¶
type EncryptFrameHead struct { FrameType uint8 // type of the frame 2-encrypt frame Version uint8 // version of encrypt frame ProtocolType uint8 // 1-rpc 2-http TotalLen uint32 // total length WorkspaceID uint32 // workspace id }
EncryptFrameHead 加密帧
func NewEncryptFrameHead ¶
func NewEncryptFrameHead() *EncryptFrameHead
func (*EncryptFrameHead) Construct ¶
func (h *EncryptFrameHead) Construct(workspaceID int, token, frameBody []byte) ([]byte, error)
Construct constructs bytes body for the whole frame.
func (*EncryptFrameHead) Extract ¶
func (h *EncryptFrameHead) Extract(buf []byte)
Extract extracts field values of the FrameHead from the buffer.
type FrameHead ¶
type FrameHead struct { FrameType uint8 // type of the frame 0-default Version uint8 // version of protocol HeaderLen uint16 // header length TotalLen uint32 // total length Reserved uint16 }
FrameHead is head of the rpc frame.
func NewFrameHead ¶
func NewFrameHead() *FrameHead
type Msg ¶
type Msg struct {
// contains filtered or unexported fields
}
Msg is the context information for a request
func NewAsyncMessage ¶
func NewMessage ¶
NewMessage create an empty message, and put it into ctx,
func (*Msg) CalleeServiceName ¶
CalleeServiceName returns callee service name.
func (*Msg) CallerServiceName ¶
CallerServiceName returns caller service name.
func (*Msg) ClientReqHead ¶
func (m *Msg) ClientReqHead() interface{}
ClientReqHead returns the request package head of client,
func (*Msg) ClientRespError ¶
ClientRespError returns client response error, which created when client call downstream.
func (*Msg) ClientRespHead ¶
func (m *Msg) ClientRespHead() interface{}
ClientRespHead returns the response package head of client.
func (*Msg) RequestTimeout ¶
RequestTimeout returns request timeout set by upstream business protocol.
func (*Msg) SerializationType ¶
SerializationType returns the value of body serialization.
func (*Msg) ServerReqHead ¶
func (m *Msg) ServerReqHead() interface{}
ServerReqHead returns the package head of request
func (*Msg) ServerRespError ¶
ServerRespError returns server response error.
func (*Msg) ServerRespHead ¶
func (m *Msg) ServerRespHead() interface{}
ServerRespHead returns the package head of response
func (*Msg) WithCallRPCName ¶
WithCallRPCName sets call rpc name.
func (*Msg) WithCalleeMethod ¶
WithCalleeMethod sets callee method.
func (*Msg) WithCalleeServiceName ¶
WithCalleeServiceName sets callee service name.
func (*Msg) WithCallerMethod ¶
WithCallerMethod sets callee method.
func (*Msg) WithCallerServiceName ¶
WithCallerServiceName sets caller servie name.
func (*Msg) WithClientReqHead ¶
func (m *Msg) WithClientReqHead(h interface{})
WithClientReqHead sets the request package head of client.
func (*Msg) WithClientRespError ¶
WithClientRespError sets client response err
func (*Msg) WithClientRespHead ¶
func (m *Msg) WithClientRespHead(h interface{})
WithClientRespHead sets the response package head of client.
func (*Msg) WithFrameCodec ¶
func (m *Msg) WithFrameCodec(f interface{})
WithFrameCodec sets frame codec.
func (*Msg) WithLocalAddr ¶
WithLocalAddr set local address.
func (*Msg) WithLogger ¶
WithLogger sets log into context message.
func (*Msg) WithRemoteAddr ¶
WithRemoteAddr sets remote address.
func (*Msg) WithRequestTimeout ¶
WithRequestTimeout sets request timeout.
func (*Msg) WithSerializationType ¶
WithSerializationType sets body serialization type of body.
func (*Msg) WithServerReqHead ¶
func (m *Msg) WithServerReqHead(h interface{})
WithServerReqHead sets the package head of request
func (*Msg) WithServerRespError ¶
WithServerRespError sets server response error.
func (*Msg) WithServerRespHead ¶
func (m *Msg) WithServerRespHead(h interface{})
WithServerRespHead sets the package head returns to upstream.
type SignFrameHead ¶
type SignFrameHead struct { FrameType uint8 // type of the frame 1-signature frame Version uint8 // version of signature frame ProtocolType uint8 // 1-rpc 2-http TotalLen uint32 // total length WorkSpaceID uint32 // workspace length Sign []byte // signature 32 个字节,md5(workspace_id+secret+frame) }
SignFrameHead is head of signature of frame
func NewSignFrameHead ¶
func NewSignFrameHead() *SignFrameHead
func (*SignFrameHead) Construct ¶
func (h *SignFrameHead) Construct(workspaceID int, token, frameBody []byte) ([]byte, error)
Construct constructs bytes body for the whole frame.
func (*SignFrameHead) Extract ¶
func (h *SignFrameHead) Extract(buf []byte)
Extract extracts field values of the FrameHead from the buffer.
Directories
¶
Path | Synopsis |
---|---|
Package mapstructure exposes functionality to convert one arbitrary Go type into another, typically to convert a map[string]interface{} into a native Go structure.
|
Package mapstructure exposes functionality to convert one arbitrary Go type into another, typically to convert a map[string]interface{} into a native Go structure. |