-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
74 lines (66 loc) · 1.89 KB
/
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
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"fmt"
"github.com/kidstuff/toys/confg"
_ "github.com/kidstuff/toys/confg/jsonconfg"
"github.com/kidstuff/toys/locale"
"github.com/kidstuff/toys/view"
"labix.org/v2/mgo"
"net/http"
_ "net/http/pprof"
"os"
)
var (
CONFIG confg.Configurator
DBNAME string = "test"
MODELDRIVER string = "mtoy"
)
func main() {
var err error
// Configuration variable
CONFIG, err = confg.Open("jsonconfg", "glog-confg.json")
if err != nil {
panic("mgoauth: cannot load mgoauth-confg.json " + err.Error())
}
var (
// host
host = os.Getenv("OPENSHIFT_INTERNAL_IP") + ":" + os.Getenv("OPENSHIFT_INTERNAL_PORT")
// cnnStr the connection string to MongoDB
cnnStr = os.Getenv("OPENSHIFT_MONGODB_DB_URL")
// langRoot the path to language folder in file system
langRoot = os.Getenv("OPENSHIFT_REPO_DIR") + "language"
// langDefaultSet the default language set
langDefaultSet = "en"
// tmplDefaultSet the path to template folder in files system
tmplRoot = os.Getenv("OPENSHIFT_REPO_DIR") + "template"
// tmplDefaultSet the default template set
tmplDefaultSet = "default"
// rsrcRoot the path to static folder in file system
rsrcRoot = os.Getenv("OPENSHIFT_REPO_DIR") + "statics"
// rsrcPrefix the URL path for static file server
rsrcPrefix = "/statics/"
//toysignPath the URL path for toysign
toysignPath = "/"
)
//database session
dbsess, err := mgo.Dial(cnnStr)
if err != nil {
panic(err)
}
defer dbsess.Close()
//multi language support
lang := locale.NewLang(langRoot)
if err := lang.Parse(langDefaultSet); err != nil {
fmt.Println(err.Error())
}
//template for cms
tmpl := view.NewView(tmplRoot)
tmpl.SetLang(lang)
tmpl.HandleResource(rsrcPrefix, rsrcRoot)
tmpl.Watch = true
if err := tmpl.Parse(tmplDefaultSet); err != nil {
fmt.Println(err.Error())
}
http.Handle(toysignPath, Handler(toysignPath, dbsess, tmpl))
http.ListenAndServe(host, nil)
}