forked from FactomProject/factomd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventServiceParameters.go
68 lines (61 loc) · 3.12 KB
/
eventServiceParameters.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package eventservices
import (
"fmt"
"github.com/FactomProject/factomd/common/globals"
"github.com/FactomProject/factomd/events/eventconfig"
"github.com/FactomProject/factomd/log"
"github.com/FactomProject/factomd/util"
)
type EventServiceParams struct {
EnableLiveFeedAPI bool
Protocol string
Address string
OutputFormat eventconfig.EventFormat
ReplayDuringStartup bool
SendStateChangeEvents bool
BroadcastContent eventconfig.BroadcastContent
}
func selectParameters(factomParams *globals.FactomParams, config *util.FactomdConfig) *EventServiceParams {
params := new(EventServiceParams)
if factomParams != nil && len(factomParams.EventReceiverProtocol) > 0 {
params.Protocol = factomParams.EventReceiverProtocol
} else if config != nil && len(config.LiveFeedAPI.EventReceiverProtocol) > 0 {
params.Protocol = config.LiveFeedAPI.EventReceiverProtocol
} else {
params.Protocol = defaultProtocol
}
if factomParams != nil && len(factomParams.EventReceiverHost) > 0 && factomParams.EventReceiverPort > 0 {
params.Address = fmt.Sprintf("%s:%d", factomParams.EventReceiverHost, factomParams.EventReceiverPort)
} else if config != nil && len(config.LiveFeedAPI.EventReceiverHost) > 0 && config.LiveFeedAPI.EventReceiverPort > 0 {
params.Address = fmt.Sprintf("%s:%d", config.LiveFeedAPI.EventReceiverHost, config.LiveFeedAPI.EventReceiverPort)
} else {
params.Address = fmt.Sprintf("%s:%d", defaultConnectionHost, defaultConnectionPort)
}
if factomParams != nil && len(factomParams.EventFormat) > 0 {
params.OutputFormat = eventconfig.EventFormatFrom(factomParams.EventFormat, defaultOutputFormat)
} else if config != nil && len(config.LiveFeedAPI.EventFormat) > 0 {
params.OutputFormat = eventconfig.EventFormatFrom(config.LiveFeedAPI.EventFormat, defaultOutputFormat)
} else {
params.OutputFormat = defaultOutputFormat
}
params.EnableLiveFeedAPI = (factomParams != nil && factomParams.EnableLiveFeedAPI) || (config != nil && config.LiveFeedAPI.EnableLiveFeedAPI)
params.ReplayDuringStartup = (factomParams != nil && factomParams.EventReplayDuringStartup) || (config != nil && config.LiveFeedAPI.EventReplayDuringStartup)
params.SendStateChangeEvents = (factomParams != nil && factomParams.EventSendStateChange) || (config != nil && config.LiveFeedAPI.EventSendStateChange)
var err error
if factomParams != nil && len(factomParams.EventBroadcastContent) > 0 {
params.BroadcastContent, err = eventconfig.ParseBroadcastContent(factomParams.EventBroadcastContent)
if err != nil {
log.LogPrintf("livefeed", "Parameter EventBroadcastContent could not be parsed: %v\n", err)
params.BroadcastContent = eventconfig.BroadcastOnce
}
} else if config != nil && len(config.LiveFeedAPI.EventBroadcastContent) > 0 {
params.BroadcastContent, err = eventconfig.ParseBroadcastContent(config.LiveFeedAPI.EventBroadcastContent)
if err != nil {
log.LogPrintf("livefeed", "Configuration property LiveFeedAPI.EventBroadcastContent could not be parsed: %v", err)
params.BroadcastContent = eventconfig.BroadcastOnce
}
} else {
params.BroadcastContent = eventconfig.BroadcastOnce
}
return params
}