arg

package
v2.0.0-alpha.73 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

The `arg` package provides utilities for managing and processing arguments in a structured way. It is designed to facilitate handling HTTP request parameters, context data, and finalizers in a clean and organized manner, featuring:

  • Parameter Handling: efficient extraction and manipulation of parameters from various sources within HTTP requests. Parameters are parsed and stored in a way that enables easy access and processing.
  • Context Management: managing and utilizing context data throughout the request processing pipeline. This context can store important information such as user details or other request-specific data, which can be accessed by subsequent processing steps.
  • Finalizers: functions that are executed after the main processing of a request. Finalizers are useful for tasks like logging and metrics collection, ensuring that essential post-processing operations are handled effectively.
  • Internationalization: using client language preferences to apply appropriate translations to output strings, enhancing user experience across different languages.

The Args struct, which is the primary object of this package, is created and passed to [Action] by the framework.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get[T argTypes](as *Args, name string) T

func GetCSV

func GetCSV[T argTypes](as *Args, name string) ([]T, error)

func GetContext

func GetContext[T any](as *Args, name string) T

func Gets

func Gets[T argTypes](as *Args, name string) []T

Types

type Args

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

The Args struct is used to store the collection of parameters parsed from HTTP requests. It serves as a central repository for accessing and managing these parameters throughout the request handling process.

func (*Args) Add

func (as *Args) Add(key string, val any)

func (*Args) AddFinalizer

func (as *Args) AddFinalizer(f func(*Args))

func (Args) Context

func (as Args) Context(key string) any

func (*Args) Del

func (as *Args) Del(key string)

func (Args) Finalizers

func (as Args) Finalizers() []func(*Args)

func (Args) Has

func (as Args) Has(key string) bool

func (Args) HasContext

func (as Args) HasContext(key string) bool

func (*Args) Init

func (as *Args) Init()

Initialize the Args struct. This function is used internally by the framework.

func (Args) Keys

func (as Args) Keys() []string

func (Args) Localizer

func (as Args) Localizer() *message.Printer

func (*Args) Set

func (as *Args) Set(key string, val ...any)

func (Args) Value

func (as Args) Value(key string) any

func (Args) Values

func (as Args) Values(key string) []any

func (*Args) WithContext

func (as *Args) WithContext(key string, val any) *Args

WithContext adds a context entry that is passed to the next action in the chain or to finalizers. This function is typically used in "login" actions to add user information or to create a "session" after successful authentication.

The `key` parameter is the context entry key, and `val` is the corresponding value. The function returns the current Args instance to support method chaining.

func (*Args) WithLocalizer

func (as *Args) WithLocalizer(mp *message.Printer) *Args

WithLocalizer sets a *message.Printer which is used to localize output information. This function is used internally by the framework.

See here for more information on i18n/l10n capabilities of the HAP framework.

Jump to

Keyboard shortcuts

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