transformer

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package transformer provides custom transformers for schema fields.

Index

Constants

This section is empty.

Variables

View Source
var DateTransformer = newDateTransformer()

DateTransformer is a transformer that converts a string in ISO format to primitive.DateTime and vice versa.

View Source
var IDTransformer = newIDTransformer()

IDTransformer is a transformer that converts a string to primitive.ObjectID and vice versa.

Functions

This section is empty.

Types

type Transformer

type Transformer interface {
	// IsTransformationRequired reports whether the transformer is required for the given field.
	IsTransformationRequired(field reflect.StructField) bool
	// TransformForMongoDoc transforms the incoming value according to mongo requirements.
	TransformForMongoDoc(value interface{}) (interface{}, error)
	// TransformForEntityModelDoc transforms the incoming value according to entity model requirements.
	TransformForEntityModelDoc(value interface{}) (interface{}, error)
}

Transformer can transform fields in both directions i.e. from entity model to mongo doc and vice versa.

func GetRequiredTransformersForField

func GetRequiredTransformersForField(field reflect.StructField) []Transformer

GetRequiredTransformersForField returns the transformers required for the given field.

Jump to

Keyboard shortcuts

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