Skip to content

Commit d4f7c51

Browse files
author
goodsign
committed
Added type for CustomReceiverProducer func signature. cihub#39.
1 parent a499e49 commit d4f7c51

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

cfg_parser.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ const (
9191
connWriterReconnectOnMsgAttr = "reconnectonmsg"
9292
)
9393

94+
// CustomReceiverProducer is the signature of the function CfgParseParams needs to create
95+
// custom receivers.
96+
type CustomReceiverProducer func(CustomReceiverInitArgs) (CustomReceiver, error)
97+
9498
// CfgParseParams represent specific parse options or flags used by parser. It is used if seelog parser needs
9599
// some special directives or additional info to correctly parse a config.
96100
type CfgParseParams struct {
@@ -114,7 +118,7 @@ type CfgParseParams struct {
114118
// You may use this param to set custom producers in case you need to pass some context when instantiating
115119
// a custom receiver or if you frequently change custom receivers with different parameters or in any other
116120
// situation where package-level registering (RegisterReceiver) is not an option for you.
117-
CustomReceiverProducers map[string]func(initArgs CustomReceiverInitArgs) (CustomReceiver, error)
121+
CustomReceiverProducers map[string]CustomReceiverProducer
118122
}
119123

120124
func (cfg *CfgParseParams) String() string {

cfg_parser_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,12 @@ func getParserTests() []parserTest {
398398
testHeadSplitter, _ = newSplitDispatcher(defaultformatter, []interface{}{testCustomReceiver2})
399399
testExpected.LogType = syncloggerTypeFromString
400400
testExpected.RootDispatcher = testHeadSplitter
401+
fnc := func(initArgs CustomReceiverInitArgs) (CustomReceiver, error) {
402+
return &customTestReceiver{}, nil
403+
}
401404
cfg := CfgParseParams{
402-
CustomReceiverProducers: map[string]func(initArgs CustomReceiverInitArgs) (CustomReceiver, error){
403-
"custom-name-2": func(initArgs CustomReceiverInitArgs) (CustomReceiver, error) {
404-
return &customTestReceiver{}, nil
405-
},
405+
CustomReceiverProducers: map[string]CustomReceiverProducer{
406+
"custom-name-2": CustomReceiverProducer(fnc),
406407
},
407408
}
408409
testExpected.Params = &cfg

0 commit comments

Comments
 (0)