-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (35 loc) · 956 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
package main
import (
"log"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/paudelgaurav/gin-api-permissions/controller"
"github.com/paudelgaurav/gin-api-permissions/database"
"github.com/paudelgaurav/gin-api-permissions/middleware"
"github.com/paudelgaurav/gin-api-permissions/models"
)
func main() {
loadEnv()
loadDatabase()
serveApplication()
}
func loadEnv() {
err := godotenv.Load(".env")
if err != nil {
log.Fatal("Error loading .env file")
}
}
func loadDatabase() {
database.Connect()
log.Print("User Table Migrate")
if err := database.DB.AutoMigrate(&models.User{}); err != nil {
log.Fatal("problem while migrating user table")
}
}
func serveApplication() {
r := gin.Default()
r.GET("/ping", controller.Ping)
r.POST("/user", middleware.BasicAuthPermission("can_create_users"), controller.CreateUser)
r.GET("/users", middleware.BasicAuthPermission("can_list_users"), controller.GetUsers)
r.Run()
}