Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error interface {
error
Code() string
Message() string
SetMessage(message string) Error
Params() []Param
HasParam(key string) bool
AddParam(param Param) Error
}
Error is a interface for errors.
type ErrorBag ¶
type ErrorBag interface {
Error
Each(f func(path string, errs Errors) bool)
// Fails returns true if the error bag has one or more errors.
Fails() bool
// Failed returns the keys of the failed fields.
Failed() []string
// FailedAt returns true if the error bag has one or more errors for the given keys.
FailedAt(key string, codes ...string) bool
// HasError returns true if the error bag has one or more errors for the given keys.
HasError(key string) bool
// AddError adds an error to the error bag.
AddError(key string, err Error)
// GetAllErrors returns the errors in the error bag.
GetAllErrors() map[string]Errors
// GetErrors returns the errors for the given key.
GetErrors(key string) Errors
// GetError returns the error for the given key and code.
GetError(key string, code string) Error
// SetMessages sets custom error messages
SetMessages(messages map[string]map[string]string) ErrorBag
// GetMessages returns the messages in the error bag.
GetMessages() map[string][]string
// GetMessage returns the messages for the given key.
GetMessage(key string) []string
}
ErrorBag is a interface for error bags.
type ErrorBuilder ¶
ErrorBuilder is a interface for building messages.
type Rule ¶
type Rule[T any] interface { Validate(ctx context.Context, errorBuilder ErrorBuilder, value T) Error }
type Translator ¶
type Translator interface {
T(key string, params map[string]any) string
P(key string, pluralCount any, params map[string]any) string
Locale(locale string) Translator
}
Translator is the interface for translation.
type Validatable ¶
type Validatable interface {
Validate(ctx context.Context, errorBuilder ErrorBuilder) Error
}
Validatable is the interface for creating validatable types on the client side.
type Validator ¶
type Validator interface {
// Validate validates the given value.
Validate(ctx context.Context, builders ...ValidatorBuilder) ErrorBag
}
Validator is the validator interface.
type ValidatorBuilder ¶
type ValidatorBuilder interface {
// Build builds the validator.
Build(ctx ValidatorContext)
// SetAttribute sets the attribute name.
SetAttribute(attribute string) ValidatorBuilder
// GetAttribute gets the attribute name.
GetAttribute() string
// SetKey sets the attribute key parts.
SetKey(paths ...string) ValidatorBuilder
// GetKey gets the attribute key parts.
GetKey() []string
}
ValidatorBuilder is the validator builder interface.
type ValidatorContext ¶
type ValidatorContext interface {
AddValidate(key string, rule Validatable)
}
ValidatorContext is the context for validation.
Click to show internal directories.
Click to hide internal directories.