forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
48 lines (40 loc) · 1.04 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
package op_heartbeat
import (
"errors"
"github.com/ethereum-optimism/optimism/op-heartbeat/flags"
oplog "github.com/ethereum-optimism/optimism/op-service/log"
opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics"
"github.com/ethereum-optimism/optimism/op-service/oppprof"
"github.com/urfave/cli/v2"
)
type Config struct {
HTTPAddr string
HTTPPort int
Log oplog.CLIConfig
Metrics opmetrics.CLIConfig
Pprof oppprof.CLIConfig
}
func (c Config) Check() error {
if c.HTTPAddr == "" {
return errors.New("must specify a valid HTTP address")
}
if c.HTTPPort <= 0 {
return errors.New("must specify a valid HTTP port")
}
if err := c.Metrics.Check(); err != nil {
return err
}
if err := c.Pprof.Check(); err != nil {
return err
}
return nil
}
func NewConfig(ctx *cli.Context) Config {
return Config{
HTTPAddr: ctx.String(flags.HTTPAddrFlag.Name),
HTTPPort: ctx.Int(flags.HTTPPortFlag.Name),
Log: oplog.ReadCLIConfig(ctx),
Metrics: opmetrics.ReadCLIConfig(ctx),
Pprof: oppprof.ReadCLIConfig(ctx),
}
}