-
Notifications
You must be signed in to change notification settings - Fork 0
/
output_reg.go
50 lines (41 loc) · 1.08 KB
/
output_reg.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
41
42
43
44
45
46
47
48
49
50
package outputs
import (
"fmt"
"github.com/JieTrancender/nsq_consumer/libconsumer/common"
"github.com/JieTrancender/nsq_consumer/libconsumer/consumer"
"github.com/JieTrancender/nsq_consumer/libconsumer/logp"
)
var outputReg = map[string]Factory{}
type Factory func(
consumerInfo consumer.Info,
cfg *common.Config,
) (Group, error)
func FindFactory(name string) Factory {
return outputReg[name]
}
type Group struct {
Clients []Client
BatchSize int
Retry int
}
// RegisterType registers a new output type.
func RegisterType(name string, f Factory) {
if outputReg[name] != nil {
panic(fmt.Errorf("output type '%v' exists already", name))
}
outputReg[name] = f
}
func Load(
consumerInfo consumer.Info,
name string,
config *common.Config,
) (Group, error) {
logp.L().Infof("output_reg#Load %s %s", name, consumerInfo.Name)
factory := FindFactory(name)
if factory == nil {
// return Group{}, fmt.Errorf("output type %v undefined", name)
logp.L().Debugf("output_reg#Load fail, type %s is not exist", name)
return Group{}, nil
}
return factory(consumerInfo, config)
}