ctx

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Value

func Value[K comparable, V any](c IContext, key K) (V, bool)

Value returns the value associated with this context for key, or nil

Types

type BaseContext

type BaseContext struct {
	Context  context.Context
	TraceLog logger.Logger
	Req      proto.Message
	Resp     []proto.Message

	// for rpc reply
	NatsMsg *nats.Msg
}

func (*BaseContext) Deadline

func (c *BaseContext) Deadline() (deadline time.Time, ok bool)

func (*BaseContext) Done

func (c *BaseContext) Done() <-chan struct{}

func (*BaseContext) Err

func (c *BaseContext) Err() error

func (*BaseContext) GetTrace

func (c *BaseContext) GetTrace() Trace

func (*BaseContext) MustBaseContext

func (c *BaseContext) MustBaseContext() *BaseContext

func (*BaseContext) Reset

func (c *BaseContext) Reset()

func (*BaseContext) SetValue

func (c *BaseContext) SetValue(key any, value any)

func (*BaseContext) Value

func (c *BaseContext) Value(key any) any

type IContext

type IContext interface {
	context.Context
	define.Clear
	SetValue(any, any)
	// MustBaseContext implementations of IContext must contain BaseContext
	MustBaseContext() *BaseContext
	GetTrace() Trace
}

type IContextPtr

type IContextPtr[T any] interface {
	IContext
	*T
}

type Int64TraceCtx

type Int64TraceCtx = TraceCtx[IntTrace, *IntTrace]

type IntTrace

type IntTrace struct {
	basepb.IntTrace
}

func (*IntTrace) GetServerIdAndType

func (i *IntTrace) GetServerIdAndType() (int64, string)

func (*IntTrace) SetServerIdAndType

func (i *IntTrace) SetServerIdAndType(serverId int64, serverType string)

func (*IntTrace) ToHash

func (i *IntTrace) ToHash() uint64

func (*IntTrace) TraceLogField

func (i *IntTrace) TraceLogField(zc logger.Context) logger.Context

func (*IntTrace) TraceMarshalAppend

func (i *IntTrace) TraceMarshalAppend(b []byte) ([]byte, error)

func (*IntTrace) TraceMarshalFrom

func (i *IntTrace) TraceMarshalFrom(b []byte) error

func (*IntTrace) TraceMarshalSize

func (i *IntTrace) TraceMarshalSize() int

type RoleIdType

type RoleIdType interface {
	int64 | string
}

type StringTrace

type StringTrace struct {
	basepb.StringTrace
}

func (*StringTrace) GetServerIdAndType

func (i *StringTrace) GetServerIdAndType() (int64, string)

func (*StringTrace) Reset

func (i *StringTrace) Reset()

func (*StringTrace) SetServerIdAndType

func (i *StringTrace) SetServerIdAndType(serverId int64, serverType string)

func (*StringTrace) ToHash

func (i *StringTrace) ToHash() uint64

func (*StringTrace) TraceLogField

func (i *StringTrace) TraceLogField(zc logger.Context) logger.Context

func (*StringTrace) TraceMarshalAppend

func (i *StringTrace) TraceMarshalAppend(b []byte) ([]byte, error)

func (*StringTrace) TraceMarshalFrom

func (i *StringTrace) TraceMarshalFrom(b []byte) error

func (*StringTrace) TraceMarshalSize

func (i *StringTrace) TraceMarshalSize() int

type StringTraceCtx

type StringTraceCtx = TraceCtx[StringTrace, *StringTrace]

type ToHash

type ToHash interface {
	// ToHash return a hash value for cluster router msg
	// uint64 is the hash value
	// one hash one goroutine if bool is true
	ToHash() uint64
}

type Trace

type Trace interface {
	ToHash() uint64

	TraceMarshalSize() int
	// TraceMarshalAppend marshal the object to byte slice
	TraceMarshalAppend([]byte) ([]byte, error)
	// TraceMarshalFrom unmarshal the object from byte slice
	TraceMarshalFrom([]byte) error

	TraceLogField(logger.Context) logger.Context

	GetServerIdAndType() (int64, string)

	SetServerIdAndType(int64, string)

	Reset()
}

type TraceCtx

type TraceCtx[TraceData any, TP TracePtr[TraceData]] struct {
	BaseContext
	TD TraceData
}

TraceCtx is a context with a trace data, trace data can be roleID,or roleInfo, or other

func NewMarkCtx

func NewMarkCtx[TraceData any, TP TracePtr[TraceData]]() *TraceCtx[TraceData, TP]

NewMarkCtx create a new TraceCtx

func NewMarkCtxWithMark

func NewMarkCtxWithMark[TraceData any, TP TracePtr[TraceData]](traceData TraceData) *TraceCtx[TraceData, TP]

NewMarkCtxWithMark create a new TraceCtx

func (*TraceCtx[TraceData, TP]) GetTrace

func (c *TraceCtx[TraceData, TP]) GetTrace() Trace

func (*TraceCtx[TraceData, TP]) Reset

func (c *TraceCtx[TraceData, TP]) Reset()

type TracePtr

type TracePtr[T any] interface {
	Trace
	*T
}

Jump to

Keyboard shortcuts

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