bag

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorBag

type ErrorBag map[string][]string

ErrorBag is a custom type that holds a map of field selectors and their related validation errors.

func (ErrorBag) Add

func (b ErrorBag) Add(selector string, msg ...string)

Add adds an error message (or many error messages) for the given selector.

func (ErrorBag) All

func (b ErrorBag) All() map[string][]string

All returns all the errors in the error bag map.

func (ErrorBag) FirstOf

func (b ErrorBag) FirstOf(selector string) string

FirstOf returns the first error message of the given selector (if it exists).

func (ErrorBag) Has

func (b ErrorBag) Has(selector string) bool

Has checks if there is an error for the given selector in the error bag.

func (ErrorBag) IsEmpty

func (b ErrorBag) IsEmpty() bool

IsEmpty checks whether the error bag map is empty.

type InputBag

type InputBag map[string]any

InputBag is a custom type representing the validation input.

func NewInputBagFromStruct

func NewInputBagFromStruct(input any) InputBag

NewInputBagFromStruct converts the given input struct into InputBag. Note that since we use json.Marshal and json.Unmarshal for this conversion, the given struct must have exported field, and if the exported fields have json tag, keep in mind that the InputBag keys are the same as the tags.

func (InputBag) Get

func (b InputBag) Get(selector string) (any, bool)

Get retrieves the value associated with the provided selector, which may reference nested values using dot notation. For example, "user.settings.avatar" or "users.0.email". It returns the value found at the specified path and a boolean indicating whether the value exists. The returned value will be nil and false if the path does not exist in the InputBag.

func (InputBag) Has

func (b InputBag) Has(selector string) bool

Has checks if the given selector exists in the input bag. The selector can contain dots in its value for nested values. For example, "user.settings.avatar" or "users.0.email". The returned value indicates whether the selector exists in the InputBag.

Jump to

Keyboard shortcuts

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