-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmongolar.go
More file actions
80 lines (75 loc) · 1.93 KB
/
Copy pathmongolar.go
File metadata and controls
80 lines (75 loc) · 1.93 KB
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
// Copyright © 2014 Jason Smith <jasonrichardsmith@gmail.com>.
//
// Use of this source code is governed by the GPL-3
// license that can be found in the LICENSE file.
package main
import (
"github.com/mongolar/mongolar/admin"
"github.com/mongolar/mongolar/basecontrollers"
"github.com/mongolar/mongolar/configs"
"github.com/mongolar/mongolar/controller"
"github.com/mongolar/mongolar/oauthlogin"
"github.com/mongolar/mongolar/router"
"gopkg.in/mgo.v2"
"net/http"
"time"
)
func main() {
cm := controller.NewMap()
basecontrollers.GetControllerMap(cm)
admin.GetControllerMap(cm)
oauthlogin.GetControllerMap(cm)
Serve(cm)
}
func Serve(cm controller.ControllerMap) {
c, port := configs.New()
EnsureIndexes(c)
HostSwitch := router.New(c.Aliases, c.SitesMap, cm)
http.ListenAndServe(":"+port, HostSwitch)
}
func EnsureIndexes(configs *configs.Configs) {
for _, site_config := range configs.SitesMap {
db_session := site_config.DbSession.Copy()
defer db_session.Close()
duration := time.Duration(site_config.SessionExpiration * time.Hour)
i := mgo.Index{
Key: []string{"updated"},
Unique: false,
DropDups: false,
Background: true,
Sparse: false,
ExpireAfter: duration,
}
c := db_session.DB("").C("sessions")
c.EnsureIndex(i)
i = mgo.Index{
Key: []string{"path", "wildcard"},
Unique: true,
DropDups: true,
Background: true,
Sparse: false,
}
c = db_session.DB("").C("paths")
c.EnsureIndex(i)
i = mgo.Index{
Key: []string{"id", "type"},
Unique: true,
DropDups: true,
Background: true,
Sparse: false,
}
c = db_session.DB("").C("users")
duration = time.Duration(2 * time.Hour)
c.EnsureIndex(i)
i = mgo.Index{
Key: []string{"created"},
Unique: false,
DropDups: false,
Background: true,
Sparse: false,
ExpireAfter: duration,
}
c = db_session.DB("").C("forms")
c.EnsureIndex(i)
}
}