Documentation ¶
Overview ¶
Package lights provides standardized shared functionality used across all Go-based agent software running on light controller devices. Most of the agents behavior has a default setting that will be "standard" when running on devices. However, all the settings can be modified by setting a variety of environment variables. The current environment variables understood by agents include:
### INC_DEVICE_ID
Sets the device ID. The default device ID is formed using the hardware (MAC) address of the wlan0 or en0 network interfaces if they exist. For Intel Edison, wlan0 will be a reliable unique ID for each module. Override the value of the device ID by setting the `INC_DEVICE_ID` variable to any arbitrary string. Device IDs are used for creating nsq topic names and reported in logs.
### INC_NSQD
Sets the nsqd address to use when agents post messages. The default is to use the address `127.0.0.1:4150` assuming that nsqd is running locally (which is typical of an nsq deployment). You can override the setting using the INC_NSQD_TCP environment variable setting `host:port` as the value.
### INC_NSQLOOKUPD
Sets the nsqlookupd address to use when agents want to subscribe to messages. The default is to use the address `nsqlookupd.local:4161` which could be set using either rendezvous or editing the /etc/hosts file. In some cases, it is better to set the nsqlookupd address manually. The environment variable can contain more than one address separated by commas. For example:
INC_NSQLOOKUPD=192.168.0.64:4161,192.168.0.61:4161
Index ¶
- func AddrToID(addr net.HardwareAddr) string
- func AgentPort(agent string) string
- func CheckIf(err error, messages ...string) bool
- func PanicIf(err error, messages ...string)
- func PanicOrID() string
- func ParseColorCode(colorCode string) (color.Color, error)
- func PrepPath(path string) (string, error)
- func ReadFileAsStringOrPanic(path string) string
- func ReadFileOrPanic(path string) []byte
- type Command
- type DeviceID
- type FileStore
- type MockStore
- func (s *MockStore) Load(collection string) ([]string, error)
- func (s *MockStore) Read(collection, id string) (string, error)
- func (s *MockStore) Remove(collection, id string) error
- func (s *MockStore) RemoveAll(collection string) error
- func (s *MockStore) Reset()
- func (s *MockStore) Write(collection, id, value string) error
- type Pattern
- type Slot
- type Store
- type Worker
- func (w *Worker) Consumer(handler WorkerFunc) error
- func (w *Worker) Handler(route string, handler WorkerFunc) error
- func (w *Worker) Send(agent, message string)
- func (w *Worker) Start() error
- func (w *Worker) Status(agent, message string)
- func (w *Worker) Transmit(agent, route, message string, consolidate bool)
- type WorkerFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddrToID ¶
func AddrToID(addr net.HardwareAddr) string
AddrToID converts a network hardware address to a string device ID.
func CheckIf ¶
CheckIf returns true if the provided error is non-nil. If messages are provided they are logged whether the error occurred or not.
func PanicIf ¶
PanicIf checks if the provided error is non-nil and panics. If messages are provided they are logged whether the error occurred or not.
func PanicOrID ¶
func PanicOrID() string
PanicOrID either produces an ID or panics if one can't be generated.
func ParseColorCode ¶
ParseColorCode parses a color code in either #RGB or #RRGGBB formats following CSS color specifications. It returns the color found or an error if the color is not a valid color code.
func ReadFileAsStringOrPanic ¶
ReadFileAsStringOrPanic reads a file content as utf-8 encoded string or panics if there was a problem.
func ReadFileOrPanic ¶
ReadFileOrPanic reads in a file or panics if there was a problem.
Types ¶
type Command ¶
Command represents an Inception system command. Parts are split using `|` characters.
func NewCommand ¶
NewCommand parses a command string to obtain it's command, message, and ID. An error is returned if the command or message is not recognized.
type DeviceID ¶
type DeviceID struct {
ID string
}
DeviceID represents a device's ID. The class provides some extra helpers for determining equality of IDs across systems (many IDs may) be shortened to the shortest unique ID (similar to git commit IDs).
func NewID ¶
NewID produces the device ID for an agent. The ID will be taken from the following in order of priority:
1. INC_DEVICE_ID environmental variable 2. Network MAC address
func (*DeviceID) ContainedIn ¶
ContainedIn returns true if this ID is matched to any of IDs in the provided string slice.
type FileStore ¶
type FileStore struct {
Base string // The path to the file store base
}
FileStore implements the Store interface by storing each value in a file named after the item ID and folders for each collection. Note that IDs and collections must be file name friendly. On disk, the files will have a `.txt` file extension added.
func NewFileStore ¶
NewFileStore creates a new file-based Store implementation. Pass in an optional base path to use for data storage (otherwise the user's home directory is used).
type MockStore ¶
MockStore is used to test services that rely on Store implementations.
type Pattern ¶
Pattern captures all data needed for a light pattern.
func NewPattern ¶
NewPattern creates a pattern from a pattern specification string.
type Store ¶
type Store interface { // Read a value from the provided collection with a given ID. Read(collection, id string) (string, error) // Write a value to the provided collection with a given ID. Write(collection, id, value string) error // Remove a value from the provided collection with a given ID. Remove(collection, id string) error // Remove all values from the provided collection. RemoveAll(collection string) error // Load reads all the values out of a collection. Load(colection string) ([]string, error) }
Store is implemented by data storage providers for persistent configuration information.
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker takes care of the common worker tasks that all message driven agents must carry out. The worker takes care of bootstrapping the system.
func NewWorker ¶
NewWorker creates a new worker ready for configuration. Call Start() on the worker to begin processing messages. Returns an error if there was a problem creating the worker. If an ID is provided the worker will use it, otherwise an ID will automatically be generated using lights.NewID().
func (*Worker) Consumer ¶
func (w *Worker) Consumer(handler WorkerFunc) error
Consumer creates a new API /command Consumer for the worker.
func (*Worker) Handler ¶
func (w *Worker) Handler(route string, handler WorkerFunc) error
Handler registers a new API route handler for the worker.
func (*Worker) Transmit ¶
Transmit reliably sends a message to another agent using HTTP. Set consolidate to true if messages sent to the same agent and route should only transmit the last message when an agent is offline. If consolidate is false, messages queued for later delivery will all be delivered when the agent is reachable again.
type WorkerFunc ¶
WorkerFunc handles incoming string messages returning an error if the message could not be handled.