faststatus

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2017 License: MIT Imports: 7 Imported by: 0

README

Fast Status

GoDoc Go Report Card Build Status Coverage Status Stories in Ready

Simple API for sharing if a resource is free, busy, or very busy

Read more about this project:

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MagicBytes = [2]byte{0x90, 0xe9}

MagicBytes are the first two bytes of the portable binary representation of a Resource.

Functions

func IsOutOfRange

func IsOutOfRange(e error) bool

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 NewID

func NewID() (ID, error)

NewID generates a new version 4 UUID. Returns errors from reading the entropy source.

func (ID) MarshalBinary

func (id ID) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface

func (ID) MarshalText

func (id ID) MarshalText() ([]byte, error)

MarshalText outputs the id as the canonical hexadecimal representation: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.

func (*ID) UnmarshalBinary

func (id *ID) UnmarshalBinary(b []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface and enforces the 16 byte length of an ID

func (*ID) UnmarshalText

func (id *ID) UnmarshalText(txt []byte) error

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

type Resource struct {
	ID           ID
	Status       Status
	Since        time.Time
	FriendlyName string
}

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

func (r Resource) Equal(other Resource) bool

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

func (r Resource) MarshalBinary() ([]byte, error)

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

func (r Resource) MarshalJSON() ([]byte, error)

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

func (r Resource) MarshalText() ([]byte, error)

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

func (r Resource) String() 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

func (r *Resource) UnmarshalBinary(b []byte) error

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

func (r *Resource) UnmarshalJSON(raw []byte) error

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

func (r *Resource) UnmarshalText(txt []byte) error

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

func (s Status) MarshalBinary() ([]byte, error)

MarshalBinary encodes a Status to a single byte in a slice

func (Status) MarshalText

func (s Status) MarshalText() ([]byte, error)

MarshalText encodes a Status to the text representation. For readable messages, this will be of the form "free|busy|occupied".

func (Status) String

func (s Status) String() string

String returns a simple text representation of the Status. Out of range status values will be returned as "Free".

func (*Status) UnmarshalBinary

func (s *Status) UnmarshalBinary(b []byte) error

UnmarshalBinary decodes a Status from a single byte

func (*Status) UnmarshalText

func (s *Status) UnmarshalText(txt []byte) error

UnmarshalText decodes a Status from a text representation. This can include an integer as text or a case-insensitive name like "Free|BUSY|occupied"

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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