codec

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: Apache-2.0 Imports: 17 Imported by: 11

Documentation

Index

Constants

View Source
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
)
View Source
const ContextMsg = "CTX_MSG"

Variables

View Source
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")
)
View Source
var (
	MaxFrameSize = 10 * 1024 * 1024 // max size of frame.
)

Functions

func CloneContext

func CloneContext(ctx context.Context) context.Context

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 CopyMsg

func CopyMsg(dst, src *Msg)

CopyMsg copy src Msg to dst.

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

func (*FrameHead) Construct

func (h *FrameHead) Construct(header, body []byte) ([]byte, error)

Construct constructs bytes body for the whole frame.

func (*FrameHead) Extract

func (h *FrameHead) Extract(buf []byte)

Extract extracts field values of the FrameHead from the buffer.

type Msg

type Msg struct {
	// contains filtered or unexported fields
}

Msg is the context information for a request

func Message

func Message(ctx context.Context) *Msg

Message returns the message of context.

func NewAsyncMessage

func NewAsyncMessage(ctx context.Context, duration time.Duration) (context.Context, context.CancelFunc, *Msg)

func NewMessage

func NewMessage(ctx context.Context) (context.Context, *Msg)

NewMessage create an empty message, and put it into ctx,

func (*Msg) CallRPCName

func (m *Msg) CallRPCName() string

CallRPCName returns call rpc name.

func (*Msg) CalleeMethod

func (m *Msg) CalleeMethod() string

CalleeMethod returns callee method.

func (*Msg) CalleeServiceName

func (m *Msg) CalleeServiceName() string

CalleeServiceName returns callee service name.

func (*Msg) CallerMethod

func (m *Msg) CallerMethod() string

CallerMethod returns callee method.

func (*Msg) CallerServiceName

func (m *Msg) CallerServiceName() string

CallerServiceName returns caller service name.

func (*Msg) ClientReqHead

func (m *Msg) ClientReqHead() interface{}

ClientReqHead returns the request package head of client,

func (*Msg) ClientRespError

func (m *Msg) ClientRespError() error

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) Context

func (m *Msg) Context() context.Context

Context return context in message

func (*Msg) Env

func (m *Msg) Env() string

Env returns environment.

func (*Msg) FrameCodec

func (m *Msg) FrameCodec() interface{}

FrameCodec returns frame codec.

func (*Msg) LocalAddr

func (m *Msg) LocalAddr() net.Addr

LocalAddr returns local address.

func (*Msg) LogSeq

func (m *Msg) LogSeq() int

LogSeq returns logger sequence

func (*Msg) Logger

func (m *Msg) Logger() logger.Logger

Logger returns log from context message.

func (*Msg) RemoteAddr

func (m *Msg) RemoteAddr() net.Addr

RemoteAddr returns remote address.

func (*Msg) RequestID

func (m *Msg) RequestID() uint64

RequestID returns request id.

func (*Msg) RequestTimeout

func (m *Msg) RequestTimeout() time.Duration

RequestTimeout returns request timeout set by upstream business protocol.

func (*Msg) SerializationType

func (m *Msg) SerializationType() int

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

func (m *Msg) ServerRespError() *errs.Error

ServerRespError returns server response error.

func (*Msg) ServerRespHead

func (m *Msg) ServerRespHead() interface{}

ServerRespHead returns the package head of response

func (*Msg) SpanID

func (m *Msg) SpanID() uint64

SpanID returns span id.

func (*Msg) TraceID

func (m *Msg) TraceID() string

TraceID returns trace id.

func (*Msg) WithCallRPCName

func (m *Msg) WithCallRPCName(s string)

WithCallRPCName sets call rpc name.

func (*Msg) WithCalleeMethod

func (m *Msg) WithCalleeMethod(s string)

WithCalleeMethod sets callee method.

func (*Msg) WithCalleeServiceName

func (m *Msg) WithCalleeServiceName(s string)

WithCalleeServiceName sets callee service name.

func (*Msg) WithCallerMethod

func (m *Msg) WithCallerMethod(s string)

WithCallerMethod sets callee method.

func (*Msg) WithCallerServiceName

func (m *Msg) WithCallerServiceName(s string)

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

func (m *Msg) WithClientRespError(e error)

WithClientRespError sets client response err

func (*Msg) WithClientRespHead

func (m *Msg) WithClientRespHead(h interface{})

WithClientRespHead sets the response package head of client.

func (*Msg) WithEnv

func (m *Msg) WithEnv(env string)

WithEnv sets environment.

func (*Msg) WithFrameCodec

func (m *Msg) WithFrameCodec(f interface{})

WithFrameCodec sets frame codec.

func (*Msg) WithLocalAddr

func (m *Msg) WithLocalAddr(addr net.Addr)

WithLocalAddr set local address.

func (*Msg) WithLogger

func (m *Msg) WithLogger(l logger.Logger)

WithLogger sets log into context message.

func (*Msg) WithRemoteAddr

func (m *Msg) WithRemoteAddr(addr net.Addr)

WithRemoteAddr sets remote address.

func (*Msg) WithRequestID

func (m *Msg) WithRequestID(id uint64)

WithRequestID sets request id.

func (*Msg) WithRequestTimeout

func (m *Msg) WithRequestTimeout(t time.Duration)

WithRequestTimeout sets request timeout.

func (*Msg) WithSerializationType

func (m *Msg) WithSerializationType(t int)

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

func (m *Msg) WithServerRespError(e error)

WithServerRespError sets server response error.

func (*Msg) WithServerRespHead

func (m *Msg) WithServerRespHead(h interface{})

WithServerRespHead sets the package head returns to upstream.

func (*Msg) WithSpanID

func (m *Msg) WithSpanID(id uint64)

WithSpanID sets span id.

func (*Msg) WithTraceID

func (m *Msg) WithTraceID(id string)

WithTraceID sets trace id.

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.

Jump to

Keyboard shortcuts

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