traceable_context

package module
Version: v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2020 License: MIT Imports: 3 Imported by: 5

README

Traceable Context

Traceable Context is a wrapper around go context which will provide a way to share a traceable UUID between different contexts

  • New context
package main

import (
    "github.com/google/uuid"
    "github.com/tryfix/traceable-context"
)

func main() {
 ctx := traceable_context.WithUUID(uuid.New())
}
    
  • Context from a parent context
    parent := contect.Background()
    ctx := traceable_context.WithUUID(parent, uuid.New())

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Background

func Background() context.Context

func FromContext

func FromContext(ctx context.Context) uuid.UUID

FromContext extracts the UUID from a given context

Types

type TraceableContext

type TraceableContext interface {
	context.Context
	// UUID returns the uuid inside the context
	UUID() uuid.UUID
}

TraceableContext wrap the go context with a traceable uuid

func FromContextWithUUID

func FromContextWithUUID(parent context.Context, uuid uuid.UUID) TraceableContext

FromContextWithUUID creates a new traceable context from a given parent context and a UUID

func WithCancel

func WithCancel(parent context.Context) (ctx TraceableContext, cancel context.CancelFunc)

func WithDeadline

func WithDeadline(parent context.Context, deadline time.Time) (ctx TraceableContext, cancel context.CancelFunc)

func WithTimeout

func WithTimeout(parent context.Context, timeout time.Duration) (ctx TraceableContext, cancel context.CancelFunc)

func WithUUID

func WithUUID(uuid uuid.UUID) TraceableContext

WithUUID creates a new traceable context from a given UUID

func WithValue

func WithValue(parent context.Context, key, val interface{}) TraceableContext

Source Files

Jump to

Keyboard shortcuts

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