statping/core.go

52 lines
1.1 KiB
Go
Raw Normal View History

2018-06-10 01:31:13 +00:00
package main
2018-06-11 07:49:41 +00:00
import (
"github.com/gorilla/sessions"
2018-06-12 05:23:30 +00:00
"github.com/hunterlong/statup/plugin"
2018-06-23 04:17:57 +00:00
"github.com/hunterlong/statup/types"
2018-06-11 07:49:41 +00:00
)
2018-06-10 03:44:47 +00:00
2018-06-10 01:31:13 +00:00
type Core struct {
2018-06-23 04:17:57 +00:00
Name string `db:"name"`
Description string `db:"description"`
Config string `db:"config"`
ApiKey string `db:"api_key"`
ApiSecret string `db:"api_secret"`
Style string `db:"style"`
Footer string `db:"footer"`
Domain string `db:"domain"`
Version string `db:"version"`
Plugins []plugin.Info
Repos []PluginJSON
PluginFields []PluginSelect
Communications []*types.Communication
2018-06-24 06:44:15 +00:00
OfflineAssets bool
2018-06-10 01:31:13 +00:00
}
2018-06-19 00:01:03 +00:00
func (c *Core) Update() (*Core, error) {
res := dbSession.Collection("core").Find().Limit(1)
res.Update(c)
core = c
return c, nil
}
2018-06-22 04:02:57 +00:00
func (c Core) AllOnline() bool {
for _, s := range services {
if !s.Online {
return false
}
}
return true
}
2018-06-10 01:31:13 +00:00
func SelectCore() (*Core, error) {
2018-06-23 05:59:29 +00:00
var c *Core
err := dbSession.Collection("core").Find().One(&c)
2018-06-10 01:31:13 +00:00
if err != nil {
return nil, err
}
2018-06-23 05:59:29 +00:00
core = c
2018-06-15 04:30:10 +00:00
store = sessions.NewCookieStore([]byte(core.ApiSecret))
2018-06-23 05:59:29 +00:00
return core, err
2018-06-10 01:31:13 +00:00
}