ctx

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2025 License: MIT Imports: 11 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 BaseCtx added in v0.1.0

type BaseCtx[TraceData any, TP TracePtr[TraceData]] struct {
	Context context.Context
	Req     proto.Message
	Resp    []proto.Message

	// for rpc reply
	NatsMsg *nats.Msg
	TD      TraceData
}

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

func NewBaseCtx added in v0.1.4

func NewBaseCtx[TraceData any, TP TracePtr[TraceData]]() *BaseCtx[TraceData, TP]

NewBaseCtx create a new BaseCtx

func NewBaseCtxWithTrace added in v0.1.4

func NewBaseCtxWithTrace[TraceData any, TP TracePtr[TraceData]](traceData TraceData) *BaseCtx[TraceData, TP]

NewBaseCtxWithTrace create a new BaseCtx

func (*BaseCtx[TraceData, TP]) Deadline added in v0.1.0

func (c *BaseCtx[TraceData, TP]) Deadline() (deadline time.Time, ok bool)

func (*BaseCtx[TraceData, TP]) Debug added in v0.1.0

func (c *BaseCtx[TraceData, TP]) Debug() *logger.Event

func (*BaseCtx[TraceData, TP]) Disabled added in v0.1.0

func (c *BaseCtx[TraceData, TP]) Disabled() *logger.Event

func (*BaseCtx[TraceData, TP]) Done added in v0.1.0

func (c *BaseCtx[TraceData, TP]) Done() <-chan struct{}

func (*BaseCtx[TraceData, TP]) Err added in v0.1.0

func (c *BaseCtx[TraceData, TP]) Err() error

func (*BaseCtx[TraceData, TP]) Error added in v0.1.0

func (c *BaseCtx[TraceData, TP]) Error() *logger.Event

func (*BaseCtx[TraceData, TP]) Fatal added in v0.1.0

func (c *BaseCtx[TraceData, TP]) Fatal() *logger.Event

func (*BaseCtx[TraceData, TP]) GetTrace added in v0.1.0

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

func (*BaseCtx[TraceData, TP]) Info added in v0.1.0

func (c *BaseCtx[TraceData, TP]) Info() *logger.Event

func (*BaseCtx[TraceData, TP]) NoLevel added in v0.1.0

func (c *BaseCtx[TraceData, TP]) NoLevel() *logger.Event

func (*BaseCtx[TraceData, TP]) Panic added in v0.1.0

func (c *BaseCtx[TraceData, TP]) Panic() *logger.Event

func (*BaseCtx[TraceData, TP]) Reset added in v0.1.0

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

func (*BaseCtx[TraceData, TP]) SetValue added in v0.1.0

func (c *BaseCtx[TraceData, TP]) SetValue(key any, value any)

func (*BaseCtx[TraceData, TP]) Trace added in v0.1.0

func (c *BaseCtx[TraceData, TP]) Trace() *logger.Event

func (*BaseCtx[TraceData, TP]) Value added in v0.1.0

func (c *BaseCtx[TraceData, TP]) Value(key any) any

func (*BaseCtx[TraceData, TP]) Warn added in v0.1.0

func (c *BaseCtx[TraceData, TP]) Warn() *logger.Event

func (*BaseCtx[TraceData, TP]) WithLevel added in v0.1.0

func (c *BaseCtx[TraceData, TP]) WithLevel(level logger.Level) *logger.Event

type IContext

type IContext interface {
	context.Context
	define.Clear
	SetValue(any, any)
	GetTrace() Trace
	logger.ILogger
}

type IContextPtr

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

type Int64TraceCtx

type Int64TraceCtx = BaseCtx[IntTrace, *IntTrace]

type IntTrace

type IntTrace struct {
	basepb.IntTrace
	// contains filtered or unexported fields
}

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(e *logger.Event) *logger.Event

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
	// contains filtered or unexported fields
}

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(e *logger.Event) *logger.Event

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 = BaseCtx[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.Event) *logger.Event

	GetServerIdAndType() (int64, string)

	SetServerIdAndType(int64, string)

	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