-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (36 loc) · 879 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"
"github.com/alireza-mf/go-ecommerce/config"
"github.com/alireza-mf/go-ecommerce/db"
"github.com/alireza-mf/go-ecommerce/routers"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/mongo"
)
// Server represents server
type Server struct {
Instance *mongo.Database
Port string
ServerReady chan bool
}
func main() {
config.InitConfig()
r := gin.Default()
// CORS allows all origins
conf := cors.DefaultConfig()
conf.AllowAllOrigins = true
r.Use(cors.New(conf))
// init mongodb
mongodb, err := db.InitMongoDB()
if err != nil {
panic(err)
}
// init routes
userAPI := initUserAPI(mongodb)
productAPI := initProductAPI(mongodb)
routers.UserRouter(r, userAPI)
routers.ProductRouter(r, productAPI)
address := "127.0.0.1:" + config.GetConfig().Port
log.Fatal(r.Run(address))
}