reqctx

package
v0.0.0-...-35aec58 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2024 License: MIT Imports: 1 Imported by: 1

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

func GetValue(ctx context.Context) *Value

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

func New(requestId string) *Value

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

func (v *Value) SetIdempotencyKey(idemKey string)

SetIdempotencyKey modifies IdempotencyKey of Value in place.

func (*Value) SetUserId

func (v *Value) SetUserId(userId int64)

SetUserId modifies UserId of Value in place.

Jump to

Keyboard shortcuts

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