-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
61 lines (50 loc) · 1.13 KB
/
config.go
File metadata and controls
61 lines (50 loc) · 1.13 KB
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
package main
import (
"encoding/json"
"os"
"path"
)
type DBType string
const (
MySQL DBType = "mysql"
PG DBType = "pg"
SQLite DBType = "sqlite"
)
func (t DBType) IsValid() bool {
switch t {
case MySQL, PG, SQLite:
return true
}
return false
}
type DBConfig struct {
Type DBType `json:"type"` // used by all
Host string `json:"host"` // used by mysql, pg
Port uint `json:"port"` // used by mysql, pg
User string `json:"user"` // used by mysql, pg
Pass string `json:"pass"` // used by mysql, pg
Name string `json:"name"` // used by mysql, pg
File string `json:"file"` // used by sqlite
}
type Config struct {
Env string `json:"env"`
Databases []DBConfig `json:"databases"`
}
var config Config
func loadJsonConfig(filepath string) error {
configFile, err := os.ReadFile(path.Join(filepath, BlueprintConfigFileName))
if err != nil {
return err
}
err = json.Unmarshal(configFile, &config)
if err != nil {
return err
}
// Set default type to mysql for backward compatibility
for i := range config.Databases {
if config.Databases[i].Type == "" {
config.Databases[i].Type = MySQL
}
}
return nil
}