{"modulePath":"github.com/aatuh/validate","version":"v1.0.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package errors\n\nPackage errors provides error types and error handling utilities for validation.\n\nThe errors package defines structured error types that provide detailed information about validation failures, including field paths, error codes, and human-readable messages.\n\nKey types: - FieldError: Represents a single validation failure at a specific field path - Errors: A collection of FieldError that implements the error interface\n\nThe package also provides utility functions for error handling, filtering, and conversion to different formats (JSON, maps, etc.).\n\n## Constants\n\n```go\nconst (\n\t// Generic\n\tCodeUnknown   = \"unknown\"\n\tCodeRequired  = \"required\"\n\tCodeOmitEmpty = \"omitempty\" // informational when skipped\n\n\t// String\n\tCodeStringMin      = \"string.min\"\n\tCodeStringMax      = \"string.max\"\n\tCodeStringNonEmpty = \"string.nonempty\"\n\tCodeStringPattern  = \"string.pattern\"\n\tCodeStringOneOf    = \"string.oneof\"\n\tCodeStringPrefix   = \"string.prefix\"\n\tCodeStringSuffix   = \"string.suffix\"\n\tCodeStringURL      = \"string.url\"\n\tCodeStringUUID     = \"string.uuid\"\n\tCodeStringHost     = \"string.hostname\"\n\n\t// Number (covers ints and floats)\n\tCodeNumberMin      = \"number.min\"\n\tCodeNumberMax      = \"number.max\"\n\tCodeNumberPositive = \"number.positive\"\n\tCodeNumberNonNeg   = \"number.nonnegative\"\n\tCodeNumberBetween  = \"number.between\"\n\n\t// Slice\n\tCodeSliceMin      = \"slice.min\"\n\tCodeSliceMax      = \"slice.max\"\n\tCodeSliceUnique   = \"slice.unique\"\n\tCodeSliceContains = \"slice.contains\"\n\n\t// Map\n\tCodeMapMinKeys = \"map.minkeys\"\n\tCodeMapMaxKeys = \"map.maxkeys\"\n\n\t// Time\n\tCodeTimeNotZero = \"time.notzero\"\n\tCodeTimeBefore  = \"time.before\"\n\tCodeTimeAfter   = \"time.after\"\n\tCodeTimeBetween = \"time.between\"\n)\n```\n\n## Types\n\n```go\ntype Errors []FieldError\n```\nErrors is a collection of FieldError that implements error.\n\nThe Error() message is a single line intended for logs. For structured consumption prefer AsMap or JSON marshaling.\n\n```go\nfunc Join(errs ...error) Errors\n```\nJoin concatenates multiple error values into an Errors slice. It flattens nested Errors and ignores nils.\n\n```go\nfunc (es Errors) AsMap() map[string][]FieldError\n```\nAsMap groups errors by exact field path. The slice per key preserves original order (stable).\n\n```go\nfunc (es Errors) Error() string\n```\nError joins all error strings into one compact line.\n\n```go\nfunc (es Errors) Filter(prefix string) Errors\n```\nFilter returns errors whose Path has the given prefix. Useful for forms where fields are grouped, e.g. \"User.Addresses\".\n\n```go\nfunc (es Errors) Has(path string) bool\n```\nHas reports whether any error targets the exact path.\n\n```go\nfunc (es Errors) MarshalJSON() ([]byte, error)\n```\nMarshalJSON ensures deterministic key ordering for better diffs.\n\n```go\nfunc (es Errors) Sort()\n```\nSortByPath then Code to provide stable presentation when needed.\n\n```go\nfunc (es Errors) Unwrap() error\n```\nUnwrap allows using errors.Is/As when you wrap Errors with fmt.Errorf. Returns nil because there is no single underlying error to unwrap.\n\n```go\ntype FieldError struct {\n\tPath string `json:\"path\"`\n\t// Code is a stable machine-readable identifier, e.g. \"string.min\",\n\t// \"int.max\", \"slice.unique\". Prefer stable codes in UIs and tests.\n\tCode string `json:\"code\"`\n\t// Param carries rule parameter, e.g. 3 for min length. Keep it simple.\n\tParam any `json:\"param,omitempty\"`\n\t// Msg is the translated, human-readable message if a Translator is set.\n\tMsg string `json:\"message,omitempty\"`\n}\n```\nFieldError represents one validation failure at a specific path. Path example: \"User.Addresses\\[2].Zip\"\n\n```go\nfunc (e FieldError) String() string\n```\nString returns a concise string for logs.\n\n","path":"github.com/aatuh/validate/errors","name":"errors","synopsis":"Package errors provides error types and error handling utilities for validation.","isRedistributable":true}
