-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (38 loc) · 957 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
45
46
package main
import (
"log"
"time"
"github.com/Hidayathamir/opendiscuss/environtment"
"github.com/Hidayathamir/opendiscuss/middleware"
"github.com/Hidayathamir/opendiscuss/router"
"github.com/Hidayathamir/opendiscuss/utils"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/pkg/errors"
"gorm.io/gorm"
)
func main() {
if err := godotenv.Load(".env"); err != nil {
panic(errors.Wrap(err, "error load .env file"))
}
if err := environtment.InitEnv(); err != nil {
panic(errors.Wrap(err, "error init environtment"))
}
var db *gorm.DB
var err error
for {
db, err = utils.GetDBConnection()
if err == nil {
break
}
err = errors.Wrap(err, "error get db connection, waiting 5s before connect again")
log.Println(err)
time.Sleep(5 * time.Second)
}
r := gin.Default()
r.Use(middleware.Cors())
router.AddRouter(db, r)
if err := r.Run(); err != nil {
panic(errors.Wrap(err, "error gin router run"))
}
}