Documentation
¶
Overview ¶
Package transform provides mechanisms to transform a data source, with a specific focus on JSON data handling.
Copyright © Trevor N. Suarez (Rican7)
Index ¶
- func Bytes(data []byte, direction Direction, transformers ...Transformer) []byte
- type Direction
- type Transformer
- func AlwaysAsDirection(always Direction, transform Transformer) Transformer
- func CamelCaseKeys(lowerRepeatedCaps bool) Transformer
- func ConventionalKeys() Transformer
- func OnlyForDirection(only Direction, transform Transformer) Transformer
- func ReverseDirection(transform Transformer) Transformer
- func ValidIdentifierKeys() Transformer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Direction ¶
type Direction bool
Direction flags the direction of marshaling/unmarshaling (encoding/decoding).
type Transformer ¶
Transformer defines a function that transforms a source bytes of data, in a given direction, to a result of bytes.
func AlwaysAsDirection ¶
func AlwaysAsDirection(always Direction, transform Transformer) Transformer
AlwaysAsDirection takes a given direction and a Transformer and returns a new Transformer that always executes the given Transformer as if the transformation direction was the given direction.
func CamelCaseKeys ¶
func CamelCaseKeys(lowerRepeatedCaps bool) Transformer
CamelCaseKeys returns a Transformer that converts every JSON "key" (or JSON object "name") in the transformed data set to be in `camelCase` style.
If the passed lowerRepeatedCaps param is `true`, then repeated capital letters (such as "URL" or "HTTP") will be converted to typical "Title" case (such as "Url" or "Http").
func ConventionalKeys ¶
func ConventionalKeys() Transformer
ConventionalKeys returns a Transformer that converts every JSON "key" (or JSON object "name") in the transformed data set, depending on the transformation direction, based on common JSON data style conventions.
For the "Marshal" direction, JSON keys are converted to `snake_case` style. For the "Unmarshal" direction, JSON keys are converted to `camelCase` style.
func OnlyForDirection ¶
func OnlyForDirection(only Direction, transform Transformer) Transformer
OnlyForDirection takes a given direction and a Transformer and returns a new Transformer that only executes the given Transformer when the transformation direction matches the given direction.
func ReverseDirection ¶
func ReverseDirection(transform Transformer) Transformer
ReverseDirection takes a Transformer and returns a new Transformer that executes the given Transformer as if the transformation direction was the oppopsite of the given direction.
func ValidIdentifierKeys ¶
func ValidIdentifierKeys() Transformer
ValidIdentifierKeys returns a Transformer that converts every JSON "key" (or JSON object "name") in the transformed data set to a key that's format matches the Go specification to be considered a valid "identifier". It does this conversion by simply stripping characters from the key/name that would otherwise make for an invalid Go identifier, according to specification.