-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
executable file
·52 lines (43 loc) · 1.32 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
package config
import (
"encoding/json"
"fmt"
"io/ioutil"
)
// Config holds options for the tool
type Config struct {
Database Database `json:"database"`
ProjectName string `json:"projectName"`
DockerComposeFilePath string `json:"dockerComposeFilePath"`
GoVersion string `json:"goVersion"`
GoDockerfileTemplate string `json:"goDockerfileTemplate"`
Groups map[string][]string `json:"groups"`
}
// Database holds config for the database service
type Database struct {
Service string `json:"service"`
AdminService string `json:"adminService"`
AdminServicePath string `json:"adminServicePath"`
Engine string `json:"engine"`
Username string `json:"username"`
Password string `json:"password"`
}
var c = &Config{}
// Init reads the config file and loads it into a global variable
func Init() error {
b, err := ioutil.ReadFile("./tools/bolt/config.json")
if err != nil {
return fmt.Errorf("failed to read config.json: %w", err)
}
if err := json.Unmarshal(b, c); err != nil {
return fmt.Errorf("failed to unmarshal config: %w", err)
}
return nil
}
// Get returns the initialised config struct
func Get() *Config {
if c == nil {
panic("config not loaded")
}
return c
}