-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
58 lines (44 loc) · 968 Bytes
/
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
package main
import (
"os"
"path"
"github.com/chainbound/apollo/db"
"github.com/chainbound/apollo/types"
"gopkg.in/yaml.v2"
)
type Config struct {
Rpc map[types.Chain]string `yaml:"rpc"`
DbSettings db.DbSettings `yaml:"postgres"`
}
func NewConfig(path string) (*Config, error) {
var c Config
f, err := os.ReadFile(path)
if err != nil {
return nil, err
}
if err = yaml.Unmarshal(f, &c); err != nil {
return nil, err
}
return &c, nil
}
func ConfigPath() (string, error) {
confDir, err := os.UserConfigDir()
if err != nil {
return "", err
}
return path.Join(confDir, "apollo", "config.yml"), nil
}
func ConfigDir() (string, error) {
confDir, err := os.UserConfigDir()
if err != nil {
return "", err
}
return path.Join(confDir, "apollo"), nil
}
func SchemaPath() (string, error) {
confDir, err := os.UserConfigDir()
if err != nil {
return "", err
}
return path.Join(confDir, "apollo", "schema.yml"), nil
}