/
config.go
69 lines (56 loc) · 1.28 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
package config
import (
"os"
"github.com/BurntSushi/toml"
)
// Config represents the `indexer.toml` file used to configure the indexer
type Config struct {
Chain ChainConfig
RPCs RPCsConfig `toml:"rpcs"`
DB DBConfig
API APIConfig
Metrics MetricsConfig
}
// ChainConfig configures of the chain being indexed
type ChainConfig struct {
// Configure known chains with the l2 chain id
Preset int
}
// RPCsConfig configures the RPC urls
type RPCsConfig struct {
L1RPC string `toml:"l1-rpc"`
L2RPC string `toml:"l2-rpc"`
}
// DBConfig configures the postgres database
type DBConfig struct {
Host string
Port int
User string
Password string
}
// APIConfig configures the API server
type APIConfig struct {
Host string
Port int
}
// MetricsConfig configures the metrics server
type MetricsConfig struct {
Host string
Port int
}
// LoadConfig loads the `indexer.toml` config file from a given path
func LoadConfig(path string) (Config, error) {
var conf Config
// Read the config file.
data, err := os.ReadFile(path)
if err != nil {
return conf, err
}
// Replace environment variables.
data = []byte(os.ExpandEnv(string(data)))
// Decode the TOML data.
if _, err := toml.Decode(string(data), &conf); err != nil {
return conf, err
}
return conf, nil
}