Documentation
¶
Index ¶
Constants ¶
const ( ContextKeyMessage = ContextKey("TRPC_MESSAGE") // ServiceSectionLength is the length of service section, // service name example: trpc.app.server.service ServiceSectionLength = 4 )
trpc context key data
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommonMeta ¶
type CommonMeta map[interface{}]interface{}
CommonMeta is common meta message.
func (CommonMeta) Clone ¶
func (c CommonMeta) Clone() CommonMeta
Clone returns a copied common meta message.
type ContextKey ¶
type ContextKey string
ContextKey is trpc context key type, the specific value is judged by interface, the interface will both judge value and type. Defining a new type can avoid string value conflict.
type Msg ¶
type Msg interface {
// WithLogger sets logger into context.
WithLogger(interface{})
// Logger returns logger from context.
Logger() interface{}
}
Msg defines core message data for Multi-protocol, business protocol should set this message when packing and unpacking data.
func EnsureMessage ¶
EnsureMessage returns context and message, if there is a message in context, returns the original one, if not, returns a new one.
func WithNewMessage ¶
WithNewMessage creates a new empty message, retrieves it from the message pool, and associates it with the provided context.
Important: The returned message is obtained from a pool to optimize memory usage. Users are responsible for manually invoking codec.PutBackMessage(msg) after use. Failure to return the message to the pool doesn't result in a traditional memory leak, where memory is never reclaimed. Instead, it may lead to a gradual increase in memory footprint over time, as messages are not being recycled as efficiently. This can eventually lead to higher than normal memory consumption, although the memory may still be eventually released.