forked from deanxv/genspark2api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (38 loc) · 882 Bytes
/
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
package main
import (
"fmt"
"genspark2api/check"
"genspark2api/common"
"genspark2api/common/config"
logger "genspark2api/common/loggger"
"genspark2api/middleware"
"genspark2api/router"
"github.com/gin-gonic/gin"
"os"
"strconv"
)
func main() {
logger.SetupLogger()
logger.SysLog(fmt.Sprintf("genspark2api %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)
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())
}
}