Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Key = "ReqCtx"
Key is used when writing to context using context.WithValue(parent, Key, Value).
Functions ¶
This section is empty.
Types ¶
type Value ¶
type Value struct { RequestId string UserId *int64 `json:"Userid,omitempty"` IdempotencyKey *string `json:"idempotencyKey,omitempty"` }
Value stores commonly used metadata to log consistently across microservices.
Uninitialized fields will not be logged due to json tag `json:"omitempty"`.
func GetValue ¶
GetValue retrieves a pointer to Value.
Value is mutable, a common usage is to retrieve from context to set values. Example:
ctx := context.WithValue(context.Background(), reqctx.Key, reqctx.New(uuid.NewString())) reqctx.GetValue(ctx).SetUserId(1)
func New ¶
New initializes *Value with a required requestId.
Value is mutable, and can be modified in-place using setter methods. Example:
valuePtr := reqctx.New(uuid.NewString()) valuePtr.SetUserId(1) fmt.Println(valuePtr.UserId) // 1
func (*Value) SetIdempotencyKey ¶
SetIdempotencyKey modifies IdempotencyKey of Value in place.
Click to show internal directories.
Click to hide internal directories.