Documentation
¶
Overview ¶
Package structo provides functionality for encoding and decoding Go structures to and from binary data and string representations, including optional encryption.
Index ¶
- Variables
- func Copy(toValue interface{}, fromValue interface{}) (err error)
- func CopyWithOption(toValue interface{}, fromValue interface{}, opt CopyOption) (err error)
- func Diff(oldStruct, newStruct interface{}) (map[string][2]interface{}, error)
- func Flatten(data interface{}) map[string]interface{}
- func InjectDefaults(ptr interface{}) error
- func TrackWithHistory(oldStruct, newStruct interface{}) (map[string]result, error)
- func Unflatten(flatMap map[string]interface{}, result interface{}) error
- type Actions
- type Converter
- type CopyOption
- type FieldNameMapping
- type TypeConverter
Constants ¶
This section is empty.
Variables ¶
View Source
var ( TimestampToTime = TypeConverter{ DstType: timestamppb.Timestamp{}, SrcType: time.Time{}, Fn: func(src interface{}) (interface{}, error) { return *timestamppb.New(src.(time.Time)), nil }, } TimeToTimestamp = TypeConverter{ DstType: time.Time{}, SrcType: timestamppb.Timestamp{}, Fn: func(src interface{}) (interface{}, error) { return src.(*timestamppb.Timestamp).AsTime(), nil }, } DefaultProtoConverters = []TypeConverter{ TimestampToTime, TimeToTimestamp, } )
Functions ¶
func CopyWithOption ¶
func CopyWithOption(toValue interface{}, fromValue interface{}, opt CopyOption) (err error)
Copy With Option
func Flatten ¶
func Flatten(data interface{}) map[string]interface{}
Flatten returns a flat map of a struct's fields using dot notation.
func TrackWithHistory ¶
TrackWithHistory returns a map of field paths and their detected actions
Types ¶
type Converter ¶
type Converter interface {
StructToBinary(data interface{}) ([]byte, error)
BinaryToStruct(data []byte, result interface{}) error
EncodeToString(data interface{}) (string, error)
DecodeFromString(data string, result interface{}) error
EncodeToStringSafe(data interface{}) (string, error)
DecodeFromStringSafe(data string, result interface{}) error
}
Converter defines the interface for encoding and decoding structures.
func NewConverter ¶
func NewConverter() Converter
NewConverter creates and returns a new instance of ConverterImpl.
type CopyOption ¶
type CopyOption struct {
// setting this value to true will ignore copying zero values of all the fields, including bools, as well as a
// struct having all it's fields set to their zero values respectively (see IsZero() in reflect/value.go)
IgnoreEmpty bool
CaseSensitive bool
DeepCopy bool
Converters []TypeConverter
// Custom field name mappings to copy values with different names in `fromValue` and `toValue` types.
// Examples can be found in `copier_field_name_mapping_test.go`.
FieldNameMapping []FieldNameMapping
}
Option sets copy options
func WithOptionsProtobuf ¶
func WithOptionsProtobuf(options ...CopyOption) CopyOption
type FieldNameMapping ¶
type TypeConverter ¶
type TypeConverter struct {
SrcType interface{}
DstType interface{}
Fn func(src interface{}) (dst interface{}, err error)
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.