-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathconfig.go
More file actions
135 lines (117 loc) · 3.42 KB
/
config.go
File metadata and controls
135 lines (117 loc) · 3.42 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package config
import "github.com/multiversx/mx-chain-core-go/core"
// Configs holds all configs
type Configs struct {
MainConfig MainConfig
ApiRoutesConfig APIRoutesConfig
Flags FlagsConfig
}
// MainConfig defines the config setup based on main config file
type MainConfig struct {
General GeneralConfig
WebSocketConnector WebSocketConfig
ConnectorApi ConnectorApiConfig
Redis RedisConfig
RabbitMQ RabbitMQConfig
ExternalWebSocketConnector WebSocketConfig
}
// GeneralConfig maps the general config section
type GeneralConfig struct {
ExternalMarshaller MarshallerConfig
AddressConverter AddressConverterConfig
CheckDuplicates bool
}
// MarshallerConfig maps the marshaller configuration
type MarshallerConfig struct {
Type string
}
// AddressConverterConfig maps the address pubkey converter configuration
type AddressConverterConfig struct {
Type string
Prefix string
Length int
}
// ConnectorApiConfig maps the connector configuration
type ConnectorApiConfig struct {
Enabled bool
Host string
Username string
Password string
}
// APIRoutesConfig holds the configuration related to Rest API routes
type APIRoutesConfig struct {
APIPackages map[string]APIPackageConfig
}
// APIPackageConfig holds the configuration for the routes of each package
type APIPackageConfig struct {
Routes []RouteConfig
}
// RouteConfig holds the configuration for a single route
type RouteConfig struct {
Name string
Open bool
Auth bool
}
// RedisConfig maps the redis configuration
type RedisConfig struct {
Url string
MasterName string
SentinelUrl string
ConnectionType string
TTL uint32
}
// RabbitMQConfig maps the rabbitMQ configuration
type RabbitMQConfig struct {
Url string
EventsExchange RabbitMQExchangeConfig
RevertEventsExchange RabbitMQExchangeConfig
FinalizedEventsExchange RabbitMQExchangeConfig
BlockTxsExchange RabbitMQExchangeConfig
BlockScrsExchange RabbitMQExchangeConfig
BlockEventsExchange RabbitMQExchangeConfig
}
// RabbitMQExchangeConfig holds the configuration for a rabbitMQ exchange
type RabbitMQExchangeConfig struct {
Name string
Type string
}
// WebSocketConfig holds the configuration for websocket observer interaction config
type WebSocketConfig struct {
Enabled bool
URL string
Mode string
RetryDurationInSec int
AcknowledgeTimeoutInSec int
WithAcknowledge bool
BlockingAckOnError bool
DropMessagesIfNoConnection bool
DataMarshallerType string
}
// FlagsConfig holds the values for CLI flags
type FlagsConfig struct {
LogLevel string
SaveLogFile bool
GeneralConfigPath string
APIConfigPath string
WorkingDir string
PublisherType string
RestApiInterface string
}
// LoadMainConfig returns a MainConfig instance by reading the provided toml file
func LoadMainConfig(filePath string) (*MainConfig, error) {
cfg := &MainConfig{}
err := core.LoadTomlFile(cfg, filePath)
if err != nil {
return nil, err
}
return cfg, err
}
// LoadAPIConfig returns a APIRoutesConfig instance by reading the provided toml file
func LoadAPIConfig(filePath string) (*APIRoutesConfig, error) {
cfg := &APIRoutesConfig{}
err := core.LoadTomlFile(cfg, filePath)
if err != nil {
return nil, err
}
return cfg, err
}