Documentation ¶
Overview ¶
Package connector ...
Implements the Connector concept in Golang.
import "github.com/hofstadter-io/connector-go" func main () { conn := connector.New("my-connector") f, b, m := foo{do:"goo"},boo{do:"be friendly"},moo{do:"farm to table"} conn.Add(f, []interface{}{b,m}) for _, named := range conn.Named() { named.Name() } for _, item := range conn.Items() { doer := item.(Doer) doer.Do() } typ := reflect.TypeOf((*Talker)(nil)).Elem() for _, item := range conn.Get(typ) { talker := item.(Talker) talker.Say() } } type Doer interface { Do() string } type Talker interface { Say() string } type foo struct { do string } func (f *foo) Do() string { return f.do } func (f *foo) Name() string { return "foo" } type boo struct { do string } func (b *boo) Do() string { return b.do } func (b *boo) Name() string { return "Casper" } func (b *boo) Say() string { return "Boooooo" } type moo struct { do string } func (m *moo) Do() string { return m.do } func (m *moo) Name() string { return "Cow" } func (m *moo) Say() string { return "MoooOOO" }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Addable ¶
type Addable interface {
Add(...interface{})
}
Addable - things which can be Add()-ed to
type Base ¶
type Base struct {
// contains filtered or unexported fields
}
Base is the base implementation
func New ¶
New creates a new Base (i.e. Connector) with the given name. Name must have a non-empty value. It should also be unique, but that is not enforced.
func (*Base) Add ¶
func (B *Base) Add(in ...interface{})
Add adds items to a Connector. Input may be a single object, slice, or any mix.
func (*Base) Clear ¶
func (B *Base) Clear()
Clear clears all items from this Connector. Will not effect connectors which this had been added to.
func (*Base) Connect ¶
Connect is the main usage function.
Connect() recursively passes a Connector object to all items so that they may consume or use any items in the Connector. Typically, we build up a root Connector and then call Connect with itself as the argument.
func (*Base) Del ¶
func (B *Base) Del(out interface{})
Del deletes an item or list of items from the connector.
type Connectable ¶
type Connectable interface {
Connect(Connector)
}
Connectable - things which consume Connectors
type Connector ¶
type Connector interface { // Connect() recursively passes a Connector object to all items // so that they may consume or use any items in the Connector. // Typically, we build up a root Connector and then // call Connect with itself as the argument. Connect(Connector) // Extracts all the items which match a given type. Go Get()'em !! Get(interface{}) []interface{} }
Connector is all the things, put together.
type Deletable ¶
type Deletable interface {
Del(interface{})
}
Deletable - things which can be Del()-ed from
type Filterable ¶
type Filterable interface {
Filter(func(interface{}) bool) []interface{}
}
Filterable - things that are Filter(func(interface{})bool)-able
type Gettable ¶
type Gettable interface {
Get(interface{}) []interface{}
}
Gettable - things which can be Get()-ed from, by type
type Indexed ¶
type Indexed interface {
Lookup(name string) interface{}
}
Indexed - things that have something to Lookup(string)
type Itemizer ¶
type Itemizer interface {
Items() []interface{}
}
Itemizer - things which have Items()
type Namer ¶
type Namer interface {
Named() []Named
}
Namer - things which hold things which have a Name()
type Searchable ¶
type Searchable interface {
Find(interface{})
}
Searchable - things that have something to Find(interface)