Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HardwareWrapper ¶
HardwareWrapper is a wrapper for the Hardware type generated from the protos to allow for custom marshalling/unmarshalling of the Hardware type
Why we need this: Since the metadata field is a json formatted string, when it's being marshaled along with the rest of the Hardware object to json format, the double quotes inside the metadata string would be automatically escaped, making it hard to read/consume.
The point of the custom marshal/unmarshal is to manually convert the metadata field between a string (for creating a hardware object) and a map (for printing) as a workaround for this problem.
func (HardwareWrapper) MarshalJSON ¶
func (h HardwareWrapper) MarshalJSON() ([]byte, error)
MarshalJSON marshals the HardwareWrapper object, with the metadata field represented as a map as the final result
Since the Hardware object's metadata field is of type string, to convert the field into a map we need to solve somewhat of a water jug problem.
1. Create an empty map A 2. Marshal Hardware object to then be unmarshaled into map A 3. Create another empty map B to unmarshal metadata string into 4. Set map B as map A's metadata field 5. Marshal map A
func (*HardwareWrapper) UnmarshalJSON ¶
func (h *HardwareWrapper) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshals the HardwareWrapper object, with the metadata field represented as a string as the final result
Since the incoming []byte b represents the metadata as a map, we can't directly unmarshal it into a Hardware object, cue water jug problem.
1. Create empty map 2. Unmarshal []byte b into map 3. Marshal metadata field 4. Set metadata string as map's metadata field 5. Marshal map to then be unmarshaled into Hardware object