-
Notifications
You must be signed in to change notification settings - Fork 1
/
controllers.go
55 lines (47 loc) · 1.48 KB
/
controllers.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
package main
import (
pressure "github.com/airdispatch/go-pressure"
"labix.org/v2/mgo"
)
type ProviderController struct {
Trackers *mgo.Collection
Servers *mgo.Collection
Engine *pressure.TemplateEngine
}
func (c *ProviderController) GetResponse(p *pressure.Request, l *pressure.Logger) (pressure.View, *pressure.HTTPError) {
var trackers []*Provider
err := c.Trackers.Find(map[string]interface{}{
"debug": IsDebug(p.Request),
}).Sort("-users").Limit(6).All(&trackers)
if err != nil {
return nil, &pressure.HTTPError{500, "500: Error loading trackers"}
}
var servers []*Provider
err = c.Servers.Find(map[string]interface{}{
"debug": IsDebug(p.Request),
}).Sort("-users").Limit(6).All(&servers)
if err != nil {
return nil, &pressure.HTTPError{500, "500: Error loading trackers"}
}
return c.Engine.NewTemplateView("pages/providers.html", map[string]interface{}{
"trackers": trackers,
"servers": servers,
}), nil
}
type AppController struct {
Collection *mgo.Collection
Engine *pressure.TemplateEngine
}
func (c *AppController) GetResponse(p *pressure.Request, l *pressure.Logger) (pressure.View, *pressure.HTTPError) {
var apps []*App
err := c.Collection.Find(map[string]interface{}{
"debug": IsDebug(p.Request),
}).Sort("-users").Limit(6).All(&apps)
if err != nil {
return nil, &pressure.HTTPError{500, "500: Error loading apps"}
}
return c.Engine.NewTemplateView("pages/apps.html", map[string]interface{}{
"apps": apps,
"mostUsed": apps,
}), nil
}