sdr

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Default = &Registry{}

Default global registry.

Functions

func HostToService

func HostToService(host, domain string) string

If the host ends with the domain, strip that domain and convert the host to a service name. E.g. asearch.search.example.com with domain example.com returns search/asearch.

In case the host does NOT end with the domain, it's returned unmodified.

func InitSourceType

func InitSourceType(src SourceType)

Called by source driver init function to register a source type.

func ServiceToHost

func ServiceToHost(service, domain string) string

Converts slash syntax service to a dot separated host name and appends domain. E.g. search/asearch with domain example.com returns asearch.search.example.com.

Types

type Message

type Message struct {
	Type  MessageType
	Index uint64

	HostKey string
	Key     string
	Value   string
}

Messages sent from SD sources to the SourceConn. You read until you receive an EndOfBatch message and then commit the changes.

The index is a sequence that increases for each batch, but might skip numbers.

type MessageType

type MessageType int
const (
	// Used to signal that there are no more immediate messages, and
	// changes should thus be applied now.
	// Only index is set in this message.
	EndOfBatch MessageType = iota

	// Updates a value for a specific host key, all fields are set
	Update

	// Deletes either a host or a value. If the entire host is deleted,
	// key will be empty string, otherwise it indicates the delete value.
	// Value field is always empty.
	Delete

	// Delete all the hosts, usually sent together with new updates for
	// all of them, if there's any left.
	// Only index is set in this message.
	Flush
)

type Registry

type Registry struct {
	Host string
	Appl string

	TLS *tls.Config
	// contains filtered or unexported fields
}

func (*Registry) AddSources

func (sdr *Registry) AddSources(conf bconf.Bconf) (n int, err error)

Instanciates any sources found in conf and adds them to the registry. Returns the number of sources found, plus any errors encounters, which will be a SourcesError. Sources might've been added even if err is non-nil. A found source will be counted even if it is already present in the registry.

func (*Registry) Close

func (sdr *Registry) Close() error

Closes all the sources, if any errors were reported this function will return a SourcesError.

Note that some drivers require that all connections are closed first, which you should do before calling this.

func (*Registry) ConnectSource

func (sdr *Registry) ConnectSource(ctx context.Context, service string, conf bconf.Bconf) (SourceConn, error)

Connect to updates for a service. conf is optional but might give hints to where to connect, and further parameters parsed by the source instance. Might return nil, nil if there was no error but no matching source instance could be found. Else returns either a connection or an error from the instance.

type SourceConn

type SourceConn interface {
	Channel() <-chan Message
	Close() error
}

An active connection for a service from an SD source. Updates are received on the channel, until you call the Close function which will close the channel from the sending side. Since channels are usually buffered there might still be some messages left after close, it's up to the user whether those need to be read or not.

type SourceInstance

type SourceInstance interface {
	Connect(ctx context.Context, service string, config bconf.Bconf) (SourceConn, error)
	Close() error
}

Interface for active driver sources. Any service might be connected, it's allowed to return nil, nil from Connect if a driver doesn't want to handle a service. Errors will be reported to the user, but only if no other driver accepted the service.

Close is called when the registry is closed.

type SourceType

type SourceType interface {
	SdrName() string
	SdrConfigKey() string

	SdrSourceSetup(conf bconf.Bconf, tls *tls.Config) (SourceInstance, error)
}

Interface implemented by SD source drivers. When AddSources is called, the SdrConfigKey is checked to exist in the conf, and if so SdrSourceSetup is called. It should setup reading from the SD source and return an instance service users can connect to.

type SourceTypeTemplate

type SourceTypeTemplate struct {
	Name, ConfigKey string
}

Many source types is just a struct with name and config key. You can use this type as a convenience.

func (*SourceTypeTemplate) SdrConfigKey

func (st *SourceTypeTemplate) SdrConfigKey() string

func (*SourceTypeTemplate) SdrName

func (st *SourceTypeTemplate) SdrName() string

type SourcesError

type SourcesError []error

Simple error wrapper for when calling multiple sources that might each return an error.

func (SourcesError) Error

func (errs SourcesError) Error() string

Jump to

Keyboard shortcuts

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