-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
49 lines (42 loc) · 1.07 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
package main
import (
"fmt"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"gpt-content-audit/check"
"gpt-content-audit/common"
"gpt-content-audit/common/config"
logger "gpt-content-audit/common/loggger"
"gpt-content-audit/middleware"
"gpt-content-audit/router"
"os"
"strconv"
"github.com/gin-contrib/sessions/cookie"
)
func main() {
logger.SetupLogger()
logger.SysLog(fmt.Sprintf("GPT Content Audit %s started", common.Version))
check.CheckEnvVariable()
if os.Getenv("GIN_MODE") != "debug" {
gin.SetMode(gin.ReleaseMode)
}
if config.DebugEnabled {
logger.SysLog("running in debug mode")
}
var err error
server := gin.New()
server.Use(gin.Recovery())
server.Use(middleware.RequestId())
middleware.SetUpLogger(server)
store := cookie.NewStore([]byte(config.SessionSecret))
server.Use(sessions.Sessions("session", store))
router.SetRouter(server)
var port = os.Getenv("PORT")
if port == "" {
port = strconv.Itoa(*common.Port)
}
err = server.Run(":" + port)
if err != nil {
logger.FatalLog("failed to start HTTP server: " + err.Error())
}
}