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 ¶
- func Get[T argTypes](as *Args, name string) T
- func GetCSV[T argTypes](as *Args, name string) ([]T, error)
- func GetContext[T any](as *Args, name string) T
- func Gets[T argTypes](as *Args, name string) []T
- type Args
- func (as *Args) Add(key string, val any)
- func (as *Args) AddFinalizer(f func(*Args))
- func (as Args) Context(key string) any
- func (as *Args) Del(key string)
- func (as Args) Finalizers() []func(*Args)
- func (as Args) Has(key string) bool
- func (as Args) HasContext(key string) bool
- func (as *Args) Init()
- func (as Args) Keys() []string
- func (as Args) Localizer() *message.Printer
- func (as *Args) Set(key string, val ...any)
- func (as Args) Value(key string) any
- func (as Args) Values(key string) []any
- func (as *Args) WithContext(key string, val any) *Args
- func (as *Args) WithLocalizer(mp *message.Printer) *Args
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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) Init ¶
func (as *Args) Init()
Initialize the Args struct. This function is used internally by the framework.
func (*Args) WithContext ¶
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.