-
Notifications
You must be signed in to change notification settings - Fork 894
/
config.go
55 lines (47 loc) · 1.16 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
package core
import (
"fmt"
"strconv"
"github.com/celestiaorg/celestia-node/libs/utils"
)
var MetricsEnabled bool
// Config combines all configuration fields for managing the relationship with a Core node.
type Config struct {
IP string
RPCPort string
GRPCPort string
}
// DefaultConfig returns default configuration for managing the
// node's connection to a Celestia-Core endpoint.
func DefaultConfig() Config {
return Config{
IP: "",
RPCPort: "26657",
GRPCPort: "9090",
}
}
// Validate performs basic validation of the config.
func (cfg *Config) Validate() error {
if !cfg.IsEndpointConfigured() {
return nil
}
ip, err := utils.ValidateAddr(cfg.IP)
if err != nil {
return err
}
cfg.IP = ip
_, err = strconv.Atoi(cfg.RPCPort)
if err != nil {
return fmt.Errorf("nodebuilder/core: invalid rpc port: %s", err.Error())
}
_, err = strconv.Atoi(cfg.GRPCPort)
if err != nil {
return fmt.Errorf("nodebuilder/core: invalid grpc port: %s", err.Error())
}
return nil
}
// IsEndpointConfigured returns whether a core endpoint has been set
// on the config (true if set).
func (cfg *Config) IsEndpointConfigured() bool {
return cfg.IP != ""
}