Documentation
¶
Index ¶
- func ScrubAny(ptr any)
- func ScrubString[S ~string](ptr **S)
- type AtomicSchema
- func Atomic[T comparable]() AtomicSchema[T, T]
- func AtomicFrom[T comparable, R any](convert func(*T) (*R, error)) AtomicSchema[T, R]
- func Float() AtomicSchema[float64, float64]
- func FloatFrom[T comparable]() AtomicSchema[T, float64]
- func Int() AtomicSchema[int, int]
- func IntFrom[T constraints.Integer]() AtomicSchema[T, int]
- func String() AtomicSchema[string, string]
- func StringFrom[T comparable]() AtomicSchema[T, string]
- func (s AtomicSchema[T, R]) Default(value T) AtomicSchema[T, R]
- func (AtomicSchema[T, R]) ForType() reflect.Type
- func (s AtomicSchema[T, R]) IsRequired() bool
- func (s AtomicSchema[T, R]) OmitZero() AtomicSchema[T, R]
- func (s AtomicSchema[T, R]) Process(data *T) error
- func (s AtomicSchema[T, R]) Required() AtomicSchema[T, R]
- func (s AtomicSchema[T, R]) Test(tests ...Test[R]) AtomicSchema[T, R]
- func (s AtomicSchema[T, R]) WithRequired(value bool) IAtomicOrPtrSchema
- type CastOpt
- type Decoder
- type Error
- type FieldMeta
- type IAtomicOrPtrSchema
- type IMapSchema
- type ISliceSchema
- type IStructSchema
- type ListError
- type M
- type MapError
- type MapSchema
- type PtrSchema
- type Schema
- type SliceSchema
- type StructSchema
- func (s StructSchema[T]) Cast(src []byte, deserialize func([]byte, any) error, opts ...CastOpt) (T, error)
- func (s StructSchema[T]) CastJSON(src []byte, opts ...CastOpt) (T, error)
- func (s StructSchema[T]) CastToAny(src []byte, deserialize func([]byte, any) error, opts ...CastOpt) (any, error)
- func (s StructSchema[T]) Decode(dec Decoder, opts ...CastOpt) (T, error)
- func (s StructSchema[T]) Extend(fields M) StructSchema[T]
- func (s StructSchema[T]) Fields() M
- func (s StructSchema[T]) ForType() reflect.Type
- func (s StructSchema[T]) Meta() map[string]FieldMeta
- func (s StructSchema[T]) Process(ptr *T) error
- func (s StructSchema[T]) WithFields(fields M) IStructSchema
- type Test
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ScrubAny ¶
func ScrubAny(ptr any)
ScrubAny replaces "" with nil in *string recursively of any Go type
func ScrubString ¶
func ScrubString[S ~string](ptr **S)
ScrubString replaces "" with nil of *string. Simplified non-reflect version of ScrubAny
Types ¶
type AtomicSchema ¶
type AtomicSchema[T comparable, R any] struct { // contains filtered or unexported fields }
AtomicSchema is a schema designed to describe scalar Go types or those that do not need to be recursively processed internally (ex. decimal.Decimal). Features: - Convert input data into another (from T to R) for further validations - Mark as required (check if value is Go zero-value) - Set default if value is zero - Set of Test predicates for validation
func Atomic ¶
func Atomic[T comparable]() AtomicSchema[T, T]
func AtomicFrom ¶
func AtomicFrom[T comparable, R any](convert func(*T) (*R, error)) AtomicSchema[T, R]
func FloatFrom ¶
func FloatFrom[T comparable]() AtomicSchema[T, float64]
FloatFrom shorthand with conversion. Supported types in order: - float32/64 and its type definitions - json.Number
func IntFrom ¶
func IntFrom[T constraints.Integer]() AtomicSchema[T, int]
IntFrom shorthand with conversion
func StringFrom ¶
func StringFrom[T comparable]() AtomicSchema[T, string]
StringFrom shorthand with conversion. Supported types in order: - fmt.Stringer - string and its type definitions
func (AtomicSchema[T, R]) Default ¶
func (s AtomicSchema[T, R]) Default(value T) AtomicSchema[T, R]
func (AtomicSchema[T, R]) ForType ¶
func (AtomicSchema[T, R]) ForType() reflect.Type
func (AtomicSchema[T, R]) IsRequired ¶
func (s AtomicSchema[T, R]) IsRequired() bool
func (AtomicSchema[T, R]) OmitZero ¶
func (s AtomicSchema[T, R]) OmitZero() AtomicSchema[T, R]
OmitZero Deprecated: for optional parameters use PtrSchema, this method is for backward compatibility
func (AtomicSchema[T, R]) Process ¶
func (s AtomicSchema[T, R]) Process(data *T) error
Process may return ListError
func (AtomicSchema[T, R]) Required ¶
func (s AtomicSchema[T, R]) Required() AtomicSchema[T, R]
func (AtomicSchema[T, R]) Test ¶
func (s AtomicSchema[T, R]) Test(tests ...Test[R]) AtomicSchema[T, R]
func (AtomicSchema[T, R]) WithRequired ¶
func (s AtomicSchema[T, R]) WithRequired(value bool) IAtomicOrPtrSchema
type IAtomicOrPtrSchema ¶
type IAtomicOrPtrSchema interface {
Schema
IsRequired() bool
WithRequired(value bool) IAtomicOrPtrSchema
}
type IMapSchema ¶
type IMapSchema interface {
Schema
// contains filtered or unexported methods
}
type ISliceSchema ¶
type ISliceSchema interface {
Schema
Inner() Schema
WithInner(inner Schema) ISliceSchema
}
type IStructSchema ¶
type ListError ¶
type ListError []Error
func (ListError) JSON ¶
func (e ListError) JSON() json.RawMessage
type MapSchema ¶
type MapSchema[M ~map[K]V, K comparable, V any] struct { // contains filtered or unexported fields }
MapSchema represents a generic map type. There's no subschema support for key/value yet.
func Map ¶
func Map[M ~map[K]V, K comparable, V any]() MapSchema[M, K, V]
type PtrSchema ¶
type PtrSchema[To any] struct { // contains filtered or unexported fields }
PtrSchema wraps inner Schema assuming input data as pointer. Features: - Mark a pointer as required (non-nil) - Process internal schema
func (PtrSchema[T]) IsRequired ¶
func (PtrSchema[To]) WithRequired ¶
func (s PtrSchema[To]) WithRequired(value bool) IAtomicOrPtrSchema
type SliceSchema ¶
type SliceSchema[S ~[]T, T any] struct { // contains filtered or unexported fields }
SliceSchema wraps inner Schema assuming input data as slice. Features: - Run slice-specific tests (see ecto/slices subpackage) - Process internal schema
func Slice ¶
func Slice[S ~[]T, T any](inner Schema) SliceSchema[S, T]
func (SliceSchema[S, T]) ForType ¶
func (SliceSchema[S, T]) ForType() reflect.Type
func (SliceSchema[S, T]) Inner ¶
func (s SliceSchema[S, T]) Inner() Schema
func (SliceSchema[S, T]) Process ¶
func (s SliceSchema[S, T]) Process(data []T) error
Process may return ListError (for list tests) or MapError for individual element errors. Map key is a stringified slice index
func (SliceSchema[S, T]) Test ¶
func (s SliceSchema[S, T]) Test(tests ...Test[S]) SliceSchema[S, T]
func (SliceSchema[S, T]) WithInner ¶
func (s SliceSchema[S, T]) WithInner(inner Schema) ISliceSchema
type StructSchema ¶
type StructSchema[T any] struct { // contains filtered or unexported fields }
StructSchema represents schema for struct types via hashmap as a struct field to its schema
func Struct ¶
func Struct[T any](fields M) StructSchema[T]
func (StructSchema[T]) Cast ¶
func (s StructSchema[T]) Cast(src []byte, deserialize func([]byte, any) error, opts ...CastOpt) (T, error)
Cast deserializes bytes into type and runs Process.
func (StructSchema[T]) CastJSON ¶
func (s StructSchema[T]) CastJSON(src []byte, opts ...CastOpt) (T, error)
CastJSON is shorthand for Cast with json.Unmarshal deserializer
func (StructSchema[T]) Decode ¶
func (s StructSchema[T]) Decode(dec Decoder, opts ...CastOpt) (T, error)
Decode decoding into T from external Decoder and runs Process
func (StructSchema[T]) Extend ¶
func (s StructSchema[T]) Extend(fields M) StructSchema[T]
Extend existing schema
func (StructSchema[T]) Fields ¶
func (s StructSchema[T]) Fields() M
func (StructSchema[T]) ForType ¶
func (s StructSchema[T]) ForType() reflect.Type
func (StructSchema[T]) Meta ¶
func (s StructSchema[T]) Meta() map[string]FieldMeta
func (StructSchema[T]) Process ¶
func (s StructSchema[T]) Process(ptr *T) error
Process may return MapError
func (StructSchema[T]) WithFields ¶
func (s StructSchema[T]) WithFields(fields M) IStructSchema
WithFields overwrites existing schema fields