-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
48 lines (39 loc) · 851 Bytes
/
main.go
File metadata and controls
48 lines (39 loc) · 851 Bytes
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
package main
import (
"log"
"net/http"
"os"
"time"
"github.com/sl4ureano/Severino/utils"
"github.com/gin-gonic/gin"
"github.com/sl4ureano/Severino/endpoint"
"github.com/sl4ureano/Severino/models"
_ "github.com/go-sql-driver/mysql"
"github.com/joho/godotenv"
)
func main() {
initEnv()
utils.InitLog()
models.InitDB()
models.InitCron()
router := endpoint.GetMainEngine()
router.Use(gin.LoggerWithWriter(utils.LogWriter))
router.Use(gin.Recovery())
port := os.Getenv("PORT")
s := &http.Server{
Addr: ":" + port,
Handler: router,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
s.ListenAndServe()
}
func initEnv() {
fileName := ".env_dev"
if utils.IsProd() {
fileName = ".env"
}
if err := godotenv.Load(fileName); err != nil {
log.Fatalf("Error loading %s file", fileName)
}
}