/
flow_channel.go
40 lines (31 loc) · 1.1 KB
/
flow_channel.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package metathings_device_cloud_service
import (
"errors"
"sync"
pb "github.com/nayotta/metathings/proto/deviced"
)
var (
ErrUnsupportedPushFrameToFlowChannelDriver = errors.New("unsupported push frame to flow channel driver")
)
type PushFrameToFlowChannel interface {
Channel() <-chan *pb.OpFrame
Close() error
}
type PushFrameToFlowChannelFactory interface {
New(args ...interface{}) (PushFrameToFlowChannel, error)
}
var push_frame_to_flow_channel_factories map[string]PushFrameToFlowChannelFactory
var push_frame_to_flow_channel_factories_once sync.Once
func register_push_frame_to_flow_channel_factory(name string, fty PushFrameToFlowChannelFactory) {
push_frame_to_flow_channel_factories_once.Do(func() {
push_frame_to_flow_channel_factories = make(map[string]PushFrameToFlowChannelFactory)
})
push_frame_to_flow_channel_factories[name] = fty
}
func NewPushFrameToFlowChannel(name string, args ...interface{}) (PushFrameToFlowChannel, error) {
fty, ok := push_frame_to_flow_channel_factories[name]
if !ok {
return nil, ErrUnsupportedPushFrameToFlowChannelDriver
}
return fty.New(args...)
}