forked from josephspurrier/gowebapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gowebapi.go
63 lines (49 loc) · 1.46 KB
/
gowebapi.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
package main
import (
"encoding/json"
"log"
"os"
"runtime"
"app/controller"
"app/route"
"app/shared/database"
"app/shared/email"
"app/shared/jsonconfig"
"app/shared/server"
)
// *****************************************************************************
// 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 email settings
email.Configure(config.Email)
// Connect to database
database.Connect(config.Database)
// Load the controller routes
controller.Load()
// 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"`
Server server.Server `json:"Server"`
}
// ParseJSON unmarshals bytes to structs
func (c *configuration) ParseJSON(b []byte) error {
return json.Unmarshal(b, &c)
}