-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathconfig.go
45 lines (36 loc) · 1.09 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
package flags
import (
"fmt"
common "github.com/base-org/blob-archiver/common/flags"
oplog "github.com/ethereum-optimism/optimism/op-service/log"
opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics"
"github.com/urfave/cli/v2"
)
type APIConfig struct {
LogConfig oplog.CLIConfig
MetricsConfig opmetrics.CLIConfig
BeaconConfig common.BeaconConfig
StorageConfig common.StorageConfig
ListenAddr string
}
func (c APIConfig) Check() error {
if err := c.StorageConfig.Check(); err != nil {
return fmt.Errorf("storage config check failed: %w", err)
}
if err := c.BeaconConfig.Check(); err != nil {
return fmt.Errorf("beacon config check failed: %w", err)
}
if c.ListenAddr == "" {
return fmt.Errorf("listen address must be set")
}
return nil
}
func ReadConfig(cliCtx *cli.Context) APIConfig {
return APIConfig{
LogConfig: oplog.ReadCLIConfig(cliCtx),
MetricsConfig: opmetrics.ReadCLIConfig(cliCtx),
BeaconConfig: common.NewBeaconConfig(cliCtx),
StorageConfig: common.NewStorageConfig(cliCtx),
ListenAddr: cliCtx.String(ListenAddressFlag.Name),
}
}