Documentation ¶
Overview ¶
Package numorstring implements a set of type definitions that represent either a number or a string. In a JSON/YAML representation each type is a single field, but the marshalling/unmarshalling deals with 3 fields in each type struct, one indicating the type, a string value (for string type), and a numerical value (for number type).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Float32OrString ¶
type Float32OrString struct { Type NumOrStringType NumVal float32 StrVal string }
Float32OrString is a type that can hold an float32 or a string. When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type. This allows you to have, for example, a JSON field that can accept a name or number.
func (Float32OrString) MarshalJSON ¶
func (f Float32OrString) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaller interface.
func (*Float32OrString) NumValue ¶
func (f *Float32OrString) NumValue() (int, error)
NumValue returns the NumVal if type Int, or if it is a String, will attempt a conversion to int.
func (*Float32OrString) String ¶
func (f *Float32OrString) String() string
String returns the string value, or the Itoa of the int value.
func (*Float32OrString) UnmarshalJSON ¶
func (f *Float32OrString) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the json.Unmarshaller interface.
type Int32OrString ¶
type Int32OrString struct { Type NumOrStringType NumVal int32 StrVal string }
Int32OrString is a type that can hold an int32 or a string. When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type. This allows you to have, for example, a JSON field that can accept a name or number.
func (Int32OrString) MarshalJSON ¶
func (i Int32OrString) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaller interface.
func (*Int32OrString) NumValue ¶
func (i *Int32OrString) NumValue() (int, error)
NumValue returns the NumVal if type Int, or if it is a String, will attempt a conversion to int.
func (*Int32OrString) String ¶
func (i *Int32OrString) String() string
String returns the string value, or the Itoa of the int value.
func (*Int32OrString) UnmarshalJSON ¶
func (i *Int32OrString) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the json.Unmarshaller interface.
type NumOrStringType ¶
type NumOrStringType int
Type represents the stored type of Int32OrString.
const ( NumOrStringNum NumOrStringType = iota // The structure holds a number. NumOrStringString // The structure holds a string. )
type Protocol ¶
type Protocol struct {
Int32OrString
}