-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
47 lines (38 loc) · 865 Bytes
/
server.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
package main
import (
"log"
"time"
db "github.com/KrishKashiwala/go-crud-arch/database"
"github.com/KrishKashiwala/go-crud-arch/routes"
"github.com/gin-gonic/gin"
cors "github.com/itsjamie/gin-cors"
"github.com/joho/godotenv"
"gorm.io/gorm"
)
func init() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading in .env file")
}
}
type Repository struct {
DB *gorm.DB
}
func main() {
// db connection
db.Setup()
gin.SetMode(gin.ReleaseMode)
router := gin.Default()
// Set up CORS middleware options
router.Use(cors.Middleware(cors.Config{
Origins: "*",
Methods: "GET, PUT, POST, DELETE",
RequestHeaders: "Origin, Authorization, Content-Type",
ExposedHeaders: "",
MaxAge: 50 * time.Second,
Credentials: false,
ValidateHeaders: false,
}))
routes.RouteServer(router)
router.Run()
}