numorstring

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2017 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package numorstring implements a set of type definitions that in YAML or JSON format may be represented by either a number or a string.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ASNumber

type ASNumber uint32

func ASNumberFromString

func ASNumberFromString(s string) (ASNumber, error)

ASNumberFromString creates an ASNumber struct from a string value. The string value may simply be a number or may be the ASN in dotted notation.

func (ASNumber) String

func (a ASNumber) String() string

String returns the string value, or the Itoa of the uint value.

func (*ASNumber) UnmarshalJSON

func (a *ASNumber) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaller uinterface.

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 {
	MinPort uint16
	MaxPort uint16
}

func PortFromRange

func PortFromRange(minPort, maxPort uint16) (Port, error)

PortFromRange creates a Port struct representing a range of ports.

func PortFromString

func PortFromString(s string) (Port, error)

PortFromString creates a Port struct from its string representation. A port may either be single value "1234" or a range of values "100:200".

func SinglePort

func SinglePort(port uint16) Port

SinglePort creates a Port struct representing a single port.

func (Port) MarshalJSON

func (p Port) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface.

func (Port) String

func (p Port) String() string

String returns the string value. If the min and max port are the same this returns a single string representation of the port number, otherwise if returns a colon separated range of ports.

func (*Port) UnmarshalJSON

func (p *Port) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaller interface.

type Protocol

type Protocol Uint8OrString

func ProtocolFromInt

func ProtocolFromInt(p uint8) Protocol

ProtocolFromInt creates a Protocol struct from an integer value.

func ProtocolFromString

func ProtocolFromString(p string) Protocol

ProtocolFromString creates a Protocol struct from a string value.

func (Protocol) MarshalJSON

func (p Protocol) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface.

func (Protocol) NumValue

func (p Protocol) NumValue() (uint8, error)

NumValue returns the NumVal if type Int, or if it is a String, will attempt a conversion to int.

func (Protocol) String

func (p Protocol) String() string

String returns the string value, or the Itoa of the int value.

func (Protocol) SupportsPorts

func (p Protocol) SupportsPorts() bool

SupportsProtocols returns whether this protocol supports ports. This returns true if the numerical or string verion of the protocol indicates TCP (6) or UDP (17).

func (*Protocol) UnmarshalJSON

func (p *Protocol) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaller interface.

type Uint8OrString

type Uint8OrString struct {
	Type   NumOrStringType
	NumVal uint8
	StrVal string
}

UInt8OrString is a type that can hold an uint8 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 (Uint8OrString) MarshalJSON

func (i Uint8OrString) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface.

func (Uint8OrString) NumValue

func (i Uint8OrString) NumValue() (uint8, error)

NumValue returns the NumVal if type Int, or if it is a String, will attempt a conversion to int.

func (Uint8OrString) String

func (i Uint8OrString) String() string

String returns the string value, or the Itoa of the int value.

func (*Uint8OrString) UnmarshalJSON

func (i *Uint8OrString) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaller interface.

Jump to

Keyboard shortcuts

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