Documentation ¶
Index ¶
Constants ¶
const TSLayout = "2006-01-02T15:04:05.000Z"
TSLayout is the layout to be used in the timestamp marshaling/unmarshaling everywhere. The timezone must always be UTC.
Variables ¶
This section is empty.
Functions ¶
func Convert ¶
func Convert(to, from interface{}) (err error)
Convert transforms the value of from into to, by translating the structure from into a set of events (go-structform.Visitor) that can applied to the value given by to. The operation fails if the values are not compatible (for example trying to convert an object into an int). To `to` parameter must be a pointer, otherwise the operation fails.
Go structures can influence the transformation via tags using the `struct` namespace. If the tag is missing, the structs field names are used. Additional options are separates by `,`. options:
`squash`, `inline`: The fields in the child struct/map are assumed to be inlined, without reporting a sub-oject. `omitempty`: The field is not converted if it is "empty". For example an empty string, array or `nil` pointers are assumed to be empty. In either case the original value in `to` will not be overwritten. `omit`, `-`: Do not convert the field.
Types ¶
type Converter ¶
type Converter struct {
// contains filtered or unexported fields
}
Converter converts structured data between arbitrary typed (serializable) go structures and maps/slices/arrays. It uses go-structform/gotype for input and output values each, such that any arbitrary structures can be used.
The converter computes and caches mapping operations for go structures it has visited.
func NewConverter ¶
func NewConverter() *Converter
NewConverter creates a new converter with local state for tracking known type conversations.
func (*Converter) Convert ¶
Convert transforms the value of from into to, by translating the structure from into a set of events (go-structform.Visitor) that can applied to the value given by to. The operation fails if the values are not compatible (for example trying to convert an object into an int), or `to` is no pointer.
type Time ¶
Time is an abstraction for the time.Time type
func MustParseTime ¶
MustParseTime is a convenience equivalent of the ParseTime function that panics in case of errors.
func (Time) MarshalJSON ¶
MarshalJSON implements json.Marshaler interface. The time is a quoted string in the JsTsLayout format.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON implements js.Unmarshaler interface. The time is expected to be a quoted string in TSLayout format.