-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
40 lines (35 loc) · 970 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
package indexdiff
import (
"os"
"path/filepath"
"strconv"
"strings"
"gopkg.in/ini.v1"
)
type Config struct {
Server string
Port int
Database string
User string
Password string
}
func loadConfiguration() ([]*Config, error) {
cfg, err := ini.Load(filepath.Join(filepath.Dir(os.Args[0]), "_config.ini"))
if err != nil {
return nil, err
}
cfg.BlockMode = false
configs := make([]*Config, 0, 10)
for _, section := range cfg.Sections() {
if strings.HasPrefix(section.Name(), "Database") {
config := &Config{}
config.Server = strings.TrimSpace(section.Key("Server").String())
config.Port, _ = strconv.Atoi(strings.TrimSpace(section.Key("Port").String()))
config.Database = strings.TrimSpace(section.Key("Database").String())
config.User = strings.TrimSpace(section.Key("User").String())
config.Password = strings.TrimSpace(section.Key("Password").String())
configs = append(configs, config)
}
}
return configs, nil
}