memory

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

README

authstate/memory

memory provides a bounded, expiry-aware, race-safe implementation of authstate.Store[T]. It is process-local and intended for tests, development, and single-process deployments.

store, err := memory.NewStore[oauth.Transaction](memory.Options{})

Store.Take deletes a value before returning it. Nil contexts and nil or zero store receivers return authstate.ErrInvalidOptions instead of panicking. The defaults allow 4096 entries and 256-byte keys; configuration cannot exceed 65536 entries or 4096 bytes per key.

Documentation

Overview

Package memory provides process-local authentication state storage.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	Now         func() time.Time
	MaxEntries  int
	MaxKeyBytes int
}

Options controls Store resource limits and time behavior. Zero values select conservative defaults.

type Store

type Store[T any] struct {
	// contains filtered or unexported fields
}

Store is a process-local authstate.Store intended for tests, development, and single-process deployments. Values are stored by assignment and must be treated as immutable by callers.

func NewStore

func NewStore[T any](options Options) (*Store[T], error)

NewStore constructs a bounded process-local authentication state store.

Example
package main

import (
	"context"
	"fmt"
	"time"

	"github.com/shibukawa/popcornweb/authstate/memory"
)

func main() {
	store, err := memory.NewStore[string](memory.Options{})
	if err != nil {
		panic(err)
	}
	expiresAt := time.Now().Add(time.Minute)
	if err := store.Put(context.Background(), "login-state", "opaque-correlation", expiresAt); err != nil {
		panic(err)
	}
	value, err := store.Take(context.Background(), "login-state")
	if err != nil {
		panic(err)
	}
	fmt.Println(value)
}
Output:
opaque-correlation

func (*Store[T]) Put

func (s *Store[T]) Put(ctx context.Context, key string, value T, expiresAt time.Time) error

func (*Store[T]) Take

func (s *Store[T]) Take(ctx context.Context, key string) (T, error)

Jump to

Keyboard shortcuts

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