contextHandler

package
v1.22.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: Apache-2.0 Imports: 11 Imported by: 2

README

contextHandler

contextHandler manages request-scoped context values (typically “session” related) and provides helpers to get and set those values.

Keys are derived from commonConfig session key names, and an internal identifier is created via idHelpers.Encode.

Getters

  • GetSession_ID(ctx context.Context) string
  • GetSession_UserKey(ctx context.Context) string
  • GetSession_UserCode(ctx context.Context) string
  • GetSession_Token(ctx context.Context) any
  • GetSession_Expiry(ctx context.Context) time.Time
  • GetSession_Locale(ctx context.Context) string
  • GetSession_Theme(ctx context.Context) string
  • GetSession_Timezone(ctx context.Context) string
  • GetSession_UserRole(ctx context.Context) string

Setters

  • SetSession_ID(ctx context.Context, sessionID string) context.Context
  • SetSession_UserKey(ctx context.Context, userKey string) context.Context
  • SetSession_UserCode(ctx context.Context, userCode string) context.Context
  • SetSession_Token(ctx context.Context, token any) context.Context
  • SetSession_Expiry(ctx context.Context, expiry time.Time) context.Context
  • SetSession_Locale(ctx context.Context, locale string) context.Context
  • SetSession_Theme(ctx context.Context, theme string) context.Context
  • SetSession_Timezone(ctx context.Context, timezone string) context.Context
  • SetSession_UserRole(ctx context.Context, role string) context.Context

Debugging

  • Debug(ctx context.Context, name string)

Worker Pool

  • AddWorkerPoolToContext(ctx context.Context, pool pond.Pool) context.Context — stores a worker pool in context
  • GetWorkerPool(ctx context.Context) (pond.Pool, error) — retrieves the worker pool from context
  • WorkerPoolKey — context key for the worker pool
  • ErrWorkerPoolNotFound — error returned when no pool is in context

Example

import (
    "context"
    "time"

    "github.com/mt1976/frantic-core/contextHandler"
)

func example() {
    ctx := context.Background()
    ctx = contextHandler.SetSession_ID(ctx, "abc")
    ctx = contextHandler.SetSession_Expiry(ctx, time.Now().Add(30*time.Minute))

    _ = contextHandler.GetSession_ID(ctx)
}

Documentation

Overview

Package contextHandler manages request-scoped context, including getting and setting values on application contexts.

Index

Constants

This section is empty.

Variables

View Source
var ErrWorkerPoolNotFound = fmt.Errorf("Worker pool not found in context")
View Source
var WorkerPoolKey = contextKey{/* contains filtered or unexported fields */}

Functions

func AddUserContext added in v1.22.0

func AddUserContext(ctx context.Context, userID, userName string) context.Context

func Debug added in v1.2.68

func Debug(c context.Context, name string)

func GetSession_Expiry added in v1.2.66

func GetSession_Expiry(ctx context.Context) time.Time

func GetSession_ID added in v1.2.66

func GetSession_ID(ctx context.Context) string

func GetSession_Identifier added in v1.2.66

func GetSession_Identifier() string

func GetSession_Locale added in v1.2.66

func GetSession_Locale(ctx context.Context) string

func GetSession_Theme added in v1.2.66

func GetSession_Theme(ctx context.Context) string

func GetSession_Timezone added in v1.2.66

func GetSession_Timezone(ctx context.Context) string

func GetSession_Token added in v1.2.66

func GetSession_Token(ctx context.Context) any

func GetSession_UserCode added in v1.2.66

func GetSession_UserCode(ctx context.Context) string

func GetSession_UserKey added in v1.2.66

func GetSession_UserKey(ctx context.Context) string

func GetSession_UserRole added in v1.2.68

func GetSession_UserRole(ctx context.Context) string

func GetUserDetails added in v1.22.0

func GetUserDetails() *user.User

func GetWorkerPool added in v1.20.0

func GetWorkerPool(ctx context.Context) (pond.Pool, error)

func GetWorkerPoolName added in v1.22.0

func GetWorkerPoolName(ctx context.Context) string

func NewWorkerPool added in v1.22.0

func NewWorkerPool(ctx context.Context, poolName string, poolSize int) context.Context

func SetSession_Expiry added in v1.2.66

func SetSession_Expiry(ctx context.Context, expiry time.Time) context.Context

func SetSession_ID added in v1.2.66

func SetSession_ID(ctx context.Context, sessionID string) context.Context

func SetSession_Locale added in v1.2.66

func SetSession_Locale(ctx context.Context, locale string) context.Context

func SetSession_Theme added in v1.2.66

func SetSession_Theme(ctx context.Context, theme string) context.Context

func SetSession_Timezone added in v1.2.66

func SetSession_Timezone(ctx context.Context, timezone string) context.Context

func SetSession_Token added in v1.2.66

func SetSession_Token(ctx context.Context, token any) context.Context

func SetSession_UserCode added in v1.2.66

func SetSession_UserCode(ctx context.Context, userCode string) context.Context

func SetSession_UserKey added in v1.2.66

func SetSession_UserKey(ctx context.Context, userKey string) context.Context

func SetSession_UserRole added in v1.2.68

func SetSession_UserRole(ctx context.Context, role string) context.Context

Types

This section is empty.

Jump to

Keyboard shortcuts

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