resource

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2020 License: Apache-2.0 Imports: 5 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Mgr = NewManager()

Mgr is the singleton resource manager

Functions

func Register

func Register(creator interface{})

Register is a convenience function that registers a resource creator function. See Manager.Register for details.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager initializes resources at peer startup and closes them at peer shutdown.

func NewManager

func NewManager() *Manager

NewManager returns a new resource Manager

func (*Manager) ChannelJoined

func (b *Manager) ChannelJoined(channelID string)

ChannelJoined notifies all applicable resources that the peer has joined a channel

func (*Manager) Clear

func (b *Manager) Clear()

Clear all resources. (Used by unit tests.)

func (*Manager) Close

func (b *Manager) Close()

Close closes all applicable resources (i.e. the ones that implement closable).

func (*Manager) Initialize

func (b *Manager) Initialize(providers ...interface{}) error

Initialize initializes all of the registered resources with the given set of providers.

func (*Manager) Register

func (b *Manager) Register(creator interface{})

Register registers a resource creator function. The function is invoked on peer startup. The creator function defines a set of arguments (which must all be of type interface{}, struct{}, or *struct{}) and returns a single pointer to a struct. Each of the args are resolved against a set of registered providers. If a provider is found then it is passed in as the argument value. If a provider is not found then a panic results.

Example:

func CreateMyResource(x someProvider, y someOtherProvider) *MyStruct {
	return &MyResource{x: x, y: y}
}

Register(CreateMyResource)

func (*Manager) Resources

func (b *Manager) Resources() []interface{}

Resources returns all resources

Jump to

Keyboard shortcuts

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