nameq

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package nameq is an application support library for using the information exported by the nameq service.

Index

Constants

View Source
const (
	// The directory used when an empty string is given to SetFeature or RemoveFeature.
	DefaultFeatureDir = "/etc/nameq/features"

	// The directory used when an empty string is given to NewFeatureMonitor.
	DefaultStateDir = "/run/nameq/state"
)

Variables

This section is empty.

Functions

func FeatureBuffer

func FeatureBuffer(output chan<- *Feature) chan<- *Feature

FeatureBuffer is an unbounded buffering adapter for Feature channels. The supplied channel doesn't need to be buffered.

func RemoveFeature

func RemoveFeature(featureDir, name string) error

RemoveFeature removes a local feature. DefaultFeatureDir is used if an empty string is given. Redundant calls are ok.

func SetFeature

func SetFeature(featureDir, name string, data []byte) error

SetFeature adds or updates a local feature. data must be a valid JSON document. DefaultFeatureDir is used if an empty string is given. Redundant calls are ok.

Types

type Feature

type Feature struct {
	Name string // Name of the feature.
	Host net.IP // IPv4 or IPv6 address of the host where the feature exists.
	Data []byte // JSON value if feature added or updated, or nil if removed.
}

Feature represents a momentary state of a feature on a host.

func (*Feature) String

func (f *Feature) String() string

String returns the feature name.

type FeatureDemux

type FeatureDemux map[string][]chan<- *Feature

FeatureDemux can be used to forward Features from FeatureMonitor to multiple subscribers based on the Name field.

Example:

monitor, err := nameq.NewFeatureMonitor("", nil)
if err != nil {
    return
}
defer monitor.Close()

foo := make(chan *nameq.Feature)
bar1 := make(chan *nameq.Feature)
bar2 := make(chan *nameq.Feature)

nameq.FeatureDemux{
    "foo": {
        nameq.FeatureBuffer(foo),
    },
    "bar": {
        nameq.FeatureBuffer(bar1),
        nameq.FeatureBuffer(bar2),
    },
}.Start(monitor.C)

go consume(foo)
go consume(bar1)
go consume(bar2)

func (FeatureDemux) Add

func (queues FeatureDemux) Add(name string, output chan<- *Feature)

Add a subscriber. The supplied channel should be buffered.

func (FeatureDemux) AddBuffer

func (queues FeatureDemux) AddBuffer(name string, output chan<- *Feature)

AddBuffer adds a subscriber with unbounded buffering. The supplied channel doesn't need to be buffered.

func (FeatureDemux) Start

func (outputs FeatureDemux) Start(input <-chan *Feature)

Start after adding all subscribers. Supply the FeatureMonitor's channel as the argument.

type FeatureMonitor

type FeatureMonitor struct {
	// Produces current information, followed by updates in real time.  There
	// may be seemingly redundant entries when a feature is updated rapidly.
	C <-chan *Feature

	// Boot is closed after all existing features have been delivered via C.
	// Client code is free to set this member to nil after it has been closed.
	Boot <-chan struct{}
	// contains filtered or unexported fields
}

FeatureMonitor watches the nameq runtime state for changes.

func NewFeatureMonitor

func NewFeatureMonitor(stateDir string, logger Logger) (m *FeatureMonitor, err error)

NewFeatureMonitor watches the specified state directory, or the default state directory if an empty string is given. The directory must exist. The logger is used for I/O errors, unless nil.

func (*FeatureMonitor) Close

func (m *FeatureMonitor) Close()

Close stops watching immediately and closes the channel.

type Logger

type Logger interface {
	Print(v ...interface{})
}

Logger is a subset of the standard log.Logger.

Jump to

Keyboard shortcuts

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