-
Notifications
You must be signed in to change notification settings - Fork 197
/
gowebapp.go
79 lines (64 loc) · 2.01 KB
/
gowebapp.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
package main
import (
"encoding/json"
"log"
"os"
"runtime"
"app/route"
"app/shared/database"
"app/shared/email"
"app/shared/jsonconfig"
"app/shared/recaptcha"
"app/shared/server"
"app/shared/session"
"app/shared/view"
"app/shared/view/plugin"
)
// *****************************************************************************
// Application Logic
// *****************************************************************************
func init() {
// Verbose logging with file name and line number
log.SetFlags(log.Lshortfile)
// Use all CPU cores
runtime.GOMAXPROCS(runtime.NumCPU())
}
func main() {
// Load the configuration file
jsonconfig.Load("config"+string(os.PathSeparator)+"config.json", config)
// Configure the session cookie store
session.Configure(config.Session)
// Connect to database
database.Connect(config.Database)
// Configure the Google reCAPTCHA prior to loading view plugins
recaptcha.Configure(config.Recaptcha)
// Setup the views
view.Configure(config.View)
view.LoadTemplates(config.Template.Root, config.Template.Children)
view.LoadPlugins(
plugin.TagHelper(config.View),
plugin.NoEscape(),
plugin.PrettyTime(),
recaptcha.Plugin())
// Start the listener
server.Run(route.LoadHTTP(), route.LoadHTTPS(), config.Server)
}
// *****************************************************************************
// Application Settings
// *****************************************************************************
// config the settings variable
var config = &configuration{}
// configuration contains the application settings
type configuration struct {
Database database.Info `json:"Database"`
Email email.SMTPInfo `json:"Email"`
Recaptcha recaptcha.Info `json:"Recaptcha"`
Server server.Server `json:"Server"`
Session session.Session `json:"Session"`
Template view.Template `json:"Template"`
View view.View `json:"View"`
}
// ParseJSON unmarshals bytes to structs
func (c *configuration) ParseJSON(b []byte) error {
return json.Unmarshal(b, &c)
}