/
config.go
88 lines (76 loc) · 1.75 KB
/
config.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package rpc
import (
"net"
)
// 'LocalHost' gets interpreted as ipv6
// TODO: revisit this
const LocalHost = "127.0.0.1"
const AnyLocal = "0.0.0.0"
type RPCConfig struct {
Info *ServerConfig `json:",omitempty" toml:",omitempty"`
Profiler *ServerConfig `json:",omitempty" toml:",omitempty"`
GRPC *ServerConfig `json:",omitempty" toml:",omitempty"`
Metrics *MetricsConfig `json:",omitempty" toml:",omitempty"`
Web3 *ServerConfig `json:",omitempty" toml:",omitempty"`
}
type ServerConfig struct {
Enabled bool
ListenHost string
ListenPort string
}
func (sc *ServerConfig) ListenAddress() string {
return net.JoinHostPort(sc.ListenHost, sc.ListenPort)
}
type MetricsConfig struct {
ServerConfig
MetricsPath string
BlockSampleSize int
}
func DefaultRPCConfig() *RPCConfig {
return &RPCConfig{
Info: DefaultInfoConfig(),
Profiler: DefaultProfilerConfig(),
GRPC: DefaultGRPCConfig(),
Metrics: DefaultMetricsConfig(),
Web3: DefaultWeb3Config(),
}
}
func DefaultInfoConfig() *ServerConfig {
return &ServerConfig{
Enabled: true,
ListenHost: AnyLocal,
ListenPort: "26658",
}
}
func DefaultGRPCConfig() *ServerConfig {
return &ServerConfig{
Enabled: true,
ListenHost: AnyLocal,
ListenPort: "10997",
}
}
func DefaultProfilerConfig() *ServerConfig {
return &ServerConfig{
Enabled: false,
ListenHost: AnyLocal,
ListenPort: "6060",
}
}
func DefaultMetricsConfig() *MetricsConfig {
return &MetricsConfig{
ServerConfig: ServerConfig{
Enabled: false,
ListenHost: AnyLocal,
ListenPort: "9102",
},
MetricsPath: "/metrics",
BlockSampleSize: 100,
}
}
func DefaultWeb3Config() *ServerConfig {
return &ServerConfig{
Enabled: true,
ListenHost: AnyLocal,
ListenPort: "26660",
}
}