numorstring

package
v1.0.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2016 License: Apache-2.0 Imports: 3 Imported by: 0

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 Port

type Port struct {
	Int32OrString
}

func PortFromInt

func PortFromInt(p int32) Port

func PortFromRange

func PortFromRange(from, to int32) Port

type Protocol

type Protocol struct {
	Int32OrString
}

func ProtocolFromInt

func ProtocolFromInt(p int32) Protocol

func ProtocolFromString

func ProtocolFromString(p string) Protocol

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL