serializer

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NotEmpty

func NotEmpty(value interface{}) error

NotEmpty checks if a field is not empty.

func Positive

func Positive(value interface{}) error

Positive checks if a field is a positive number.

func ValidEmail added in v1.4.0

func ValidEmail(value interface{}) error

ValidEmail checks if a string is in a valid email format.

func ValidPassword added in v1.3.0

func ValidPassword(value interface{}) error

ValidPassword checks if a password meets certain criteria.

Types

type BaseSerializer

type BaseSerializer struct {
	Fields            []string                                     // Included fields
	Validations       map[string][]func(interface{}) error         // Multiple validations per field
	Transformations   map[string]func(interface{}) interface{}     // Transformations by field
	ConditionalFields map[string]func(map[string]interface{}) bool // Conditional inclusion of fields
}

BaseSerializer is the default implementation of Serializer.

func (*BaseSerializer) Deserialize

func (s *BaseSerializer) Deserialize(input map[string]interface{}, out interface{}) error

Deserialize deserializes a map into a struct.

func (*BaseSerializer) Serialize

func (s *BaseSerializer) Serialize(data interface{}) (map[string]interface{}, error)

Serialize serializes a struct into a map with optional field filtering, transformations, and conditional fields.

func (*BaseSerializer) SerializeToXML added in v1.6.0

func (s *BaseSerializer) SerializeToXML(data interface{}) (string, error)

SerializeToXML serializes a struct into an XML string.

func (*BaseSerializer) SerializeToYAML added in v1.6.0

func (s *BaseSerializer) SerializeToYAML(data interface{}) (string, error)

SerializeToYAML serializes a struct into a YAML string.

func (*BaseSerializer) Validate

func (s *BaseSerializer) Validate(data map[string]interface{}) error

Validate checks the provided data against the validations defined in the serializer.

type Field

type Field interface {
	Validate(value interface{}) error
}

Field interface for validating field values.

type SerializationError added in v1.8.0

type SerializationError struct {
	Message string
}

SerializationError represents an error that occurred during serialization or deserialization.

func (*SerializationError) Error added in v1.8.0

func (e *SerializationError) Error() string

type Serializer

type Serializer interface {
	Serialize(interface{}) (map[string]interface{}, error)
	Deserialize(map[string]interface{}, interface{}) error
	Validate(map[string]interface{}) error
	SerializeToXML(interface{}) (string, error)
	SerializeToYAML(interface{}) (string, error)
}

Serializer interface defines the methods for serialization.

type StringField

type StringField struct {
	MaxLength int
}

StringField represents a string with validation options.

func (StringField) Validate

func (f StringField) Validate(value interface{}) error

type TransformationError added in v1.8.0

type TransformationError struct {
	Field   string
	Value   interface{}
	Message string
}

TransformationError represents an error that occurred during a transformation.

func (*TransformationError) Error added in v1.8.0

func (e *TransformationError) Error() string

type ValidationError added in v1.8.0

type ValidationError struct {
	Field   string
	Value   interface{}
	Message string
}

ValidationError represents an error that occurred during validation.

func (*ValidationError) Error added in v1.8.0

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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