forked from shunfei/cronsun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
48 lines (37 loc) · 822 Bytes
/
common.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
package cronsun
import (
"fmt"
"os"
"github.com/shunfei/cronsun/conf"
"github.com/shunfei/cronsun/db"
)
var (
initialized bool
_Uid int
)
func Init() (err error) {
if initialized {
return
}
// init id creator
if err = initID(); err != nil {
return fmt.Errorf("Init UUID Generator failed: %s", err)
}
// init config
if err = conf.Init(); err != nil {
return fmt.Errorf("Init Config failed: %s", err)
}
// init etcd client
if DefalutClient, err = NewClient(conf.Config); err != nil {
return fmt.Errorf("Connect to ETCD %s failed: %s",
conf.Config.Etcd.Endpoints, err)
}
// init mongoDB
if mgoDB, err = db.NewMdb(conf.Config.Mgo); err != nil {
return fmt.Errorf("Connect to MongoDB %s failed: %s",
conf.Config.Mgo.Hosts, err)
}
_Uid = os.Getuid()
initialized = true
return
}