context

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 0 Imported by: 0

README

tinywasm/context

Project Badges

Minimalist context library for TinyGo.

Features

  • No Maps: Uses a fixed array of structs to avoid dynamic allocations.
  • Minimal Footprint: Designed to keep binary size at a minimum.
  • TinyGo Compatible: Fully compatible with TinyGo and WASM environments.
  • Fixed Capacity: Maximum of 16 key-value pairs (prioritizes latest values).

Installation

go get github.com/tinywasm/context

Usage

import "github.com/tinywasm/context"

// Create background context
ctx := context.Background()

// Add values (Keys and Values must be strings)
ctx = context.WithValue(ctx, "user_id", "123")
ctx = context.WithValue(ctx, "role", "admin")

// Retrieve values
user := ctx.Value("user_id") // returns "123"
role := ctx.Value("role")    // returns "admin"
missing := ctx.Value("none") // returns ""

Constraints

  • Keys and Values are restricted to string type for performance and simplicity.
  • Maximum capacity of 16 key-value pairs. Exceeding this will cause a panic.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	// contains filtered or unexported fields
}

Context is a minimalist context compatible with TinyGo. No maps, no channels, uses a fixed array of 16 key-value pairs.

func Background added in v0.0.2

func Background() *Context

Background returns an empty Context (equivalent to context.Background).

func TODO added in v0.0.2

func TODO() *Context

TODO returns an empty Context (equivalent to context.TODO).

func WithValue added in v0.0.2

func WithValue(parent *Context, key, value string) *Context

WithValue creates a new Context with the additional key-value pair. Panics if the capacity of 16 pairs is exceeded.

func (*Context) Value added in v0.0.2

func (c *Context) Value(key string) string

Value searches for the value associated with key (reverse search to prioritize latest values).

Jump to

Keyboard shortcuts

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