-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
46 lines (39 loc) · 985 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
package main
import (
"fmt"
"log"
"github.com/jinzhu/configor"
)
//Config contains global app's configuration
var Config AppConfig
// AppConfig contains app's configuration
type AppConfig struct {
Server struct {
Port string `default:":80"`
}
DataDB struct {
User string
Host string
Password string
Database string
}
AppDB struct {
User string
Host string
Password string
Database string
}
}
//LoadFromFile method loads and parses config file
func (c *AppConfig) LoadFromFile(url string) {
err := configor.Load(&Config, url)
if err != nil {
log.Fatalf("Can't load the config file: %s", err)
}
}
func (c *AppConfig) DataDBSourceName() string {
return fmt.Sprintf("%s:%s@(%s)/%s?parseTime=true", c.DataDB.User, c.DataDB.Password, c.DataDB.Host, c.DataDB.Database)
}
func (c *AppConfig) AppDBSourceName() string {
return fmt.Sprintf("%s:%s@(%s)/%s?parseTime=true", c.AppDB.User, c.AppDB.Password, c.AppDB.Host, c.AppDB.Database)
}