-
Notifications
You must be signed in to change notification settings - Fork 53
/
config.go
70 lines (57 loc) · 1.46 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
package app
import (
"bytes"
"html/template"
"github.com/omni-network/omni/lib/buildinfo"
"github.com/omni-network/omni/lib/errors"
"github.com/omni-network/omni/lib/log"
"github.com/omni-network/omni/lib/netconf"
cmtos "github.com/cometbft/cometbft/libs/os"
_ "embed"
)
const (
defaultListenAddr = ":8080"
defaultExplorerDBConn = "postgres://omni:password@explorer_db:5432/omni_db"
defaultMonitoringAddr = ":26660"
defaultNetwork = netconf.Devnet
)
type Config struct {
ListenAddr string
ExplorerDBConn string
MonitoringAddr string
Network netconf.ID
}
func DefaultConfig() Config {
return Config{
ListenAddr: defaultListenAddr,
ExplorerDBConn: defaultExplorerDBConn,
MonitoringAddr: defaultMonitoringAddr,
Network: defaultNetwork,
}
}
//go:embed config.toml.tmpl
var tomlTemplate []byte
// WriteConfigTOML writes the toml graphql config to disk.
func WriteConfigTOML(cfg Config, logCfg log.Config, path string) error {
t, err := template.New("").Parse(string(tomlTemplate))
if err != nil {
return errors.Wrap(err, "parse template")
}
s := struct {
Config
Log log.Config
Version string
}{
Config: cfg,
Log: logCfg,
Version: buildinfo.Version(),
}
var buffer bytes.Buffer
if err := t.Execute(&buffer, s); err != nil {
return errors.Wrap(err, "execute template")
}
if err := cmtos.WriteFile(path, buffer.Bytes(), 0o644); err != nil {
return errors.Wrap(err, "write config")
}
return nil
}