contextkit

package
v0.211.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 2 Imported by: 2

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Detach

func Detach(parent context.Context) context.Context

Types

type ValueInContext added in v0.190.0

type ValueInContext[Key ~struct{}, Value any] struct{}
Example
package main

import (
	"context"

	"go.llib.dev/frameless/pkg/contextkit"
)

func main() {
	type MyContextKey struct{}
	type MyValueType string

	vic := contextkit.ValueInContext[MyContextKey, MyValueType]{}

	var ctx = context.Background() // empty context

	v, ok := vic.Lookup(ctx)
	_, _ = v, ok // "", false

	ctx = vic.ContextWith(ctx, "Hello, world!") // context with value

	v, ok = vic.Lookup(ctx)
	_, _ = v, ok // "Hello, world!", true
}

func (ValueInContext[Key, Value]) ContextWith added in v0.190.0

func (h ValueInContext[Key, Value]) ContextWith(ctx context.Context, v Value) context.Context

func (ValueInContext[Key, Value]) Lookup added in v0.190.0

func (h ValueInContext[Key, Value]) Lookup(ctx context.Context) (Value, bool)

Jump to

Keyboard shortcuts

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