-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
50 lines (42 loc) · 1.14 KB
/
main.go
File metadata and controls
50 lines (42 loc) · 1.14 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
package main
import (
"encoding/gob"
"fmt"
"io"
"os"
"github.com/gin-contrib/pprof"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin"
"github.com/phoon/go-forum/config"
"github.com/phoon/go-forum/handler/router"
"github.com/phoon/go-forum/repository"
"github.com/phoon/go-forum/repository/model"
)
func main() {
config.Load()
repository.Start()
gin.SetMode(config.Fields.Mode)
gin.DisableConsoleColor()
//set the gin framework log file
logf, err := os.OpenFile(config.Fields.GinLogFile, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
fmt.Println("Fail to open log file for gin framework.")
os.Exit(1)
}
defer logf.Close()
gin.DefaultWriter = io.MultiWriter(logf)
//use cookie to store session
store := cookie.NewStore([]byte(config.Fields.GinSessionKey))
store.Options(sessions.Options{
Path: "/",
MaxAge: 1296000, //15 days
HttpOnly: true,
})
gob.Register(&model.LoginInfo{}) //register for securecookie
app := gin.Default()
app.Use(sessions.Sessions("SESSION", store))
router.ApplyRoutes(app)
pprof.Register(app)
app.Run(config.Fields.Address)
}