-
Notifications
You must be signed in to change notification settings - Fork 7
/
config.go
58 lines (45 loc) · 990 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
47
48
49
50
51
52
53
54
55
56
57
58
package app
import (
"errors"
"github.com/sasbury/mini"
)
var (
appconfig = new(mini.Config)
ErrConfNotInit = errors.New("appconfig is not init, forgot to call InitAppConf()? ")
)
// InitAppConf ...
func InitAppConf() error {
err := appconfig.InitializeFromPath("./conf/app.conf")
if err != nil { // Handle errors reading the config file
return err
}
return nil
}
// Int ...
func Int(key string) int {
return int(appconfig.Integer(key, 0))
}
// String ...
func String(key string) string {
return appconfig.String(key, "")
}
// DefaultString ...
func DefaultString(key, def string) string {
return appconfig.String(key, def)
}
// Strings ...
func Strings(key string) []string {
return appconfig.Strings(key)
}
// GetConfigAuth ...
func GetConfigAuth() (string, string, error) {
if appconfig == nil {
return "", "", ErrConfNotInit
}
user := String("auth.user")
pwd := String("auth.pwd")
if user == "" {
return "jia", "jia", nil
}
return user, pwd, nil
}