-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
59 lines (49 loc) · 1.37 KB
/
main.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
package main
import (
//Our libraries
"agentdesks"
"agentdesks/controllers"
"agentdesks/utils"
//Third party libraries
"github.com/gorilla/handlers"
"github.com/julienschmidt/httprouter"
//Standard Library
"agentdesks/libs"
"agentdesks/models"
"encoding/json"
"io/ioutil"
"log"
"net/http"
"os"
)
var config agentdesks.Config
func myLoggingHandler(h http.Handler) http.Handler {
logFile, err := os.OpenFile(config.Logs.AccessLog, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
utils.PanicError(err, "Error opening access log")
return handlers.CombinedLoggingHandler(logFile, h)
}
func main() {
// Read config and initialize the connections
file, e := ioutil.ReadFile("config.json")
utils.PanicError(e, "Config read error")
e = json.Unmarshal(file, &config)
utils.PanicError(e, "Config read error")
// Establish connection pool
c := libs.InitRedis(&config)
conn := &models.Connections{
RedisConn: c,
}
defer c.Close()
// Instantiate a new router
r := httprouter.New()
// Get a Universal controller instance & initialize path hooks
uc := controllers.NewImageController(r, conn, &config)
uc.InitializeHooks()
/* Initialize middleware for request log mechanism
Redirect all logs to error log
Fire up the server
*/
errorLog := utils.InitializeErrorLog(&config)
defer errorLog.Close()
log.Fatal(http.ListenAndServe(":"+config.Port, myLoggingHandler(r)))
}