Documentation ¶
Index ¶
- Variables
- func IsOutOfRange(e error) bool
- type ID
- type Resource
- func (r Resource) Equal(other Resource) bool
- func (r Resource) MarshalBinary() ([]byte, error)
- func (r Resource) MarshalJSON() ([]byte, error)
- func (r Resource) MarshalText() ([]byte, error)
- func (r Resource) String() string
- func (r *Resource) UnmarshalBinary(b []byte) error
- func (r *Resource) UnmarshalJSON(raw []byte) error
- func (r *Resource) UnmarshalText(txt []byte) error
- type Status
Constants ¶
This section is empty.
Variables ¶
var MagicBytes = [2]byte{0x90, 0xe9}
MagicBytes are the first two bytes of the portable binary representation of a Resource.
Functions ¶
func IsOutOfRange ¶
IsOutOfRange returns true for an error indicating that the `Status` is out of range
Types ¶
type ID ¶
type ID [16]byte
ID is a UUIDv4 compatible byte array. Implementation is based on portions of github.com/satori/go.uuid.
func (ID) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface
func (ID) MarshalText ¶
MarshalText outputs the id as the canonical hexadecimal representation: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
func (*ID) UnmarshalBinary ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface and enforces the 16 byte length of an ID
func (*ID) UnmarshalText ¶
UnmarshalText populates the id with a uuid value represented by the text in the canonical form: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. While any of the dashes in the form may be left out, any non-hexadecimal characters will result in an error.
type Resource ¶
A Resource represents any resource (a person, a bathroom, a server, etc.) that needs to communicate how busy it is.
func NewResource ¶ added in v0.4.0
func NewResource() Resource
NewResource creates a new Resource with a generated ID and otherwise zero-value properties.
func (Resource) Equal ¶
Equal allows quick equality comparison for two resource values. Use this instead of the equality operator because a Resource contains a `time.Time` value, which cannot be compared with confidence.
func (Resource) MarshalBinary ¶
MarshalBinary returns a portable binary version of a Resource. The resulting binary must contain a header with MagicBytes (0x09 0xe9), a version byte, and a single byte with the length of the FriendlyName.
func (Resource) MarshalJSON ¶
MarshalJSON will return simple a simple json structure for a resource. Will not accept any Status that is out of range; see Status documentation for more information.
func (Resource) MarshalText ¶
MarshalText encodes a Resource to the text representation. In order to better stream text, the output is as follows:
{{ID}} {{Status}} {{Since}} {{FriendlyName}}
Formatted as follows:
01234567-89ab-cdef-0123-456789abcdef busy 2006-01-02T15:04:05Z07:00 My Resource
An invalid Status (out of range, etc.) will result in an error.
func (Resource) String ¶
String will return a single-line representation of a valid resource. In order to optimize for standard streams, the output is as follows:
{{ID}} {{Status}} {{Since}} {{FriendlyName}}
Formatted as follows:
01234567-89ab-cdef-0123-456789abcdef busy 2006-01-02T15:04:05Z07:00 My Resource
func (*Resource) UnmarshalBinary ¶
UnmarshalBinary replaces a Resource with the Resource represented by the binary input. The input binary must match the form of the MarshalBinary method.
func (*Resource) UnmarshalJSON ¶
UnmarshalJSON will populate a Resource with data from a json struct according to the same format as MarshalJSON. Will overwrite any values already assigned to the Resource.
func (*Resource) UnmarshalText ¶
UnmarshalText decodes a Resource from a line of text. This matches the output of the `MarshalText` method. Partial matches are only accepted missing `FriendlyName`.
type Status ¶
type Status uint8
Status represents how busy a given resource is on a scale from 0–2, where 0 (Free) is a completely unoccupied resource, 2 (Occupied) is completely occupied, and 1 (Busy) is anything between. The simplicity and flexibility of this scheme allows this to be used for any number of applications.
const ( Free Status = iota // a completely unutilized resource Busy // a resource that is being utilized, but not to capacity Occupied // a resource that is being utilized to capacity )
The following predefined Status values are the only valid status values
func (Status) MarshalBinary ¶
MarshalBinary encodes a Status to a single byte in a slice
func (Status) MarshalText ¶
MarshalText encodes a Status to the text representation. For readable messages, this will be of the form "free|busy|occupied".
func (Status) String ¶
String returns a simple text representation of the Status. Out of range status values will be returned as "Free".
func (*Status) UnmarshalBinary ¶
UnmarshalBinary decodes a Status from a single byte
func (*Status) UnmarshalText ¶
UnmarshalText decodes a Status from a text representation. This can include an integer as text or a case-insensitive name like "Free|BUSY|occupied"