-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conf.go
29 lines (23 loc) · 753 Bytes
/
conf.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
package app
import (
"fmt"
"github.com/chyroc/go-loader"
)
type Config struct {
MySQLHost string `loader:"env,key=MYSQL_HOST"`
MySQLUsername string `loader:"env,key=MYSQL_USERNAME"`
MySQLPassword string `loader:"env,key=MYSQL_PASSWORD"`
MySQLDatabase string `loader:"env,key=MYSQL_DATABASE"`
AdminUsername string `loader:"env,key=ADMIN_USERNAME"`
AdminPassword string `loader:"env,key=ADMIN_PASSWORD"`
}
func loadConf() (*Config, error) {
conf := new(Config)
if err := loader.Load(conf); err != nil {
return nil, err
}
return conf, nil
}
func (conf *Config) DSN() string {
return fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=True&loc=Local", conf.MySQLUsername, conf.MySQLPassword, conf.MySQLHost, conf.MySQLDatabase)
}