forked from ixre/gof
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
62 lines (57 loc) · 1016 Bytes
/
app.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
59
60
61
62
/**
* Copyright 2014 @ to2.net.
* name : app1.go
* author : jarryliu
* date : 2015-04-27 20:43:
* description :
* history :
*/
package gof
import (
"github.com/ixre/gof/db"
"github.com/ixre/gof/log"
"github.com/ixre/gof/shell"
"github.com/ixre/gof/storage"
"time"
)
// 应用当前的上下文
var CurrentApp App
type App interface {
// Provided db access
Db() db.Connector
// Return application configs.
Config() *Config
// return registry
Registry() *Registry
// Storage
Storage() storage.Interface
// Return a logger
Log() log.ILogger
// Application is running debug mode
Debug() bool
}
// 自动安装包
func AutoInstall(d time.Duration) {
execInstall()
if d == 0 {
d = time.Second * 15
}
t := time.NewTimer(d)
for {
select {
case <-t.C:
if err := execInstall(); err == nil {
t.Reset(d)
} else {
break
}
}
}
}
func execInstall() error {
_, _, err := shell.Run("go install .")
if err != nil {
log.Println("[ Gof][ Install]:", err)
}
return err
}