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 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) 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.
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(any) []any }
Connector is all the things, put together.
type Deletable ¶
type Deletable interface {
Del(any)
}
Deletable - things which can be Del()-ed from
type Filterable ¶
Filterable - things that are Filter(func(any)bool)-able
type Namer ¶
type Namer interface {
Named() []Named
}
Namer - things which hold things which have a Name()
type Searchable ¶
type Searchable interface {
Find(any)
}
Searchable - things that have something to Find(interface)