forked from statping/statping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.go
98 lines (86 loc) · 2.02 KB
/
core.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package core
import (
"github.com/GeertJohan/go.rice"
"github.com/hunterlong/statup/plugin"
"github.com/hunterlong/statup/types"
)
type PluginJSON types.PluginJSON
type PluginRepos types.PluginRepos
type Core struct {
Name string `db:"name" json:"name"`
Description string `db:"description" json:"name"`
Config string `db:"config" json:"-"`
ApiKey string `db:"api_key" json:"-"`
ApiSecret string `db:"api_secret" json:"-"`
Style string `db:"style" json:"-"`
Footer string `db:"footer" json:"-"`
Domain string `db:"domain" json:"domain,omitempty"`
Version string `db:"version" json:"version,omitempty"`
Services []*Service `json:"services,omitempty"`
Plugins []plugin.Info
Repos []PluginJSON
//PluginFields []PluginSelect
Communications []*Communication
OfflineAssets bool
}
var (
Configs *Config
CoreApp *Core
SqlBox *rice.Box
CssBox *rice.Box
ScssBox *rice.Box
JsBox *rice.Box
TmplBox *rice.Box
EmailBox *rice.Box
SetupMode bool
AllPlugins []plugin.PluginActions
UsingAssets bool
)
func init() {
CoreApp = new(Core)
}
func (c *Core) Update() (*Core, error) {
res := DbSession.Collection("core").Find().Limit(1)
res.Update(c)
CoreApp = c
return c, nil
}
func (c Core) UsingAssets() bool {
return UsingAssets
}
func (c Core) SassVars() string {
if !UsingAssets {
return ""
}
return OpenAsset("scss/variables.scss")
}
func (c Core) BaseSASS() string {
if !UsingAssets {
return ""
}
return OpenAsset("scss/base.scss")
}
func (c Core) MobileSASS() string {
if !UsingAssets {
return ""
}
return OpenAsset("scss/mobile.scss")
}
func (c Core) AllOnline() bool {
for _, s := range CoreApp.Services {
if !s.Online {
return false
}
}
return true
}
func SelectCore() (*Core, error) {
var c *Core
err := DbSession.Collection("core").Find().One(&c)
if err != nil {
return nil, err
}
CoreApp = c
//store = sessions.NewCookieStore([]byte(core.ApiSecret))
return CoreApp, err
}