ErrContext
type ErrContext struct {
FieldName string
FieldLabel string
FieldValue interface{}
TemplateLanguage language.Tag
// unexported template state
}
func (e *ErrContext) Error() string
func (e *ErrContext) SetTemplate(key string)
func (e *ErrContext) SetFieldLimitValue(v interface{})The result type for every validation failure. *ErrContext implements the standard error interface.
Public fields
| Field | Description |
|---|---|
FieldName | Go field name. |
FieldLabel | Resolved label (locale-aware) used as the message prefix. |
FieldValue | The original failing value. |
TemplateLanguage | The locale used to render the message. |
Error()
Returns the rendered message. The message is composed as FieldLabel + Template + FieldLimitValue, with hooks for {field} / {limit} placeholders and {{ … }} no-affix wrapping. See Error Messages for the full template grammar.
Mutators
These are typically used inside a custom checker to fine-tune the error before returning it.
SetTemplate(key string)
Swap the underlying template by key. Any previously set limit value is cleared so messages can never leak across templates.
ctx := govalid.NewErrorContext(c)
ctx.SetTemplate("alphadash") // borrow another rule's template
return ctxSetFieldLimitValue(v interface{})
Set the {limit} value (and the implicit suffix). Built-ins do this for min/max/minlen/maxlen so the rendered message includes the threshold.
ctx := govalid.NewErrorContext(c)
ctx.SetFieldLimitValue(42)
return ctxConstructors
You usually don't call these directly — return them from a custom checker.
func NewErrorContext(c CheckerContext) *ErrContext
func MakeUserDefinedError(msg string) *ErrContext
func MakeValueTypeError(c CheckerContext) *ErrContext
func MakeCheckerParamError(c CheckerContext) *ErrContext
func MakeCheckerNotFoundError(c CheckerContext) *ErrContext
func MakeFieldNotFoundError(c CheckerContext) *ErrContext