Documentation
¶
Overview ¶
Package transformer converts structured data between supported encodings and applies caller-provided transformations to the decoded value.
Index ¶
- func Apply(value any, transforms ...Transformation) (any, error)
- func Convert(data []byte, input Format, output Format) ([]byte, error)
- func Decode(data []byte, format Format) (any, error)
- func Encode(value any, format Format) ([]byte, error)
- func Validate(value any, conditions ...Condition) error
- type Condition
- func IsEmail() Condition
- func IsEthAddress() Condition
- func IsIPv4() Condition
- func IsIPv6() Condition
- func IsNumber() Condition
- func IsPhoneNumber() Condition
- func IsSolanaAddress() Condition
- func IsString() Condition
- func MustInclude(keys ...string) Condition
- func MustNotInclude(keys ...string) Condition
- func Regex(pattern string, name ...string) Condition
- type Format
- type Payload
- type Transformation
- type Transformer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
func Apply(value any, transforms ...Transformation) (any, error)
Apply runs transforms in order.
Types ¶
type Condition ¶
Condition validates a transformation value.
func IsEthAddress ¶
func IsEthAddress() Condition
IsEthAddress validates that a value is an Ethereum address.
func IsPhoneNumber ¶
func IsPhoneNumber() Condition
IsPhoneNumber validates that a value is a phone number.
func IsSolanaAddress ¶
func IsSolanaAddress() Condition
IsSolanaAddress validates that a value is a Solana public key address.
func MustInclude ¶
MustInclude validates that a payload includes all required keys.
func MustNotInclude ¶
MustNotInclude validates that a payload excludes all forbidden keys.
type Payload ¶
Payload is a decoded top-level object.
type Transformation ¶
Transformation mutates or replaces decoded data.
func Delete ¶
func Delete(keys []string, conditions ...Condition) Transformation
Delete deletes top-level map keys.
func Map ¶
func Map(mapper func(Payload) error, conditions ...Condition) Transformation
Map applies mapper to the decoded top-level map.
type Transformer ¶
type Transformer struct {
// contains filtered or unexported fields
}
Transformer decodes input data, applies transformations in order, and encodes the result into the requested output format.
func New ¶
func New(transforms ...Transformation) *Transformer
New creates a Transformer with optional transforms.
func (*Transformer) Add ¶
func (transformer *Transformer) Add(transforms ...Transformation) *Transformer
Add appends transforms to the Transformer.