-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
106 lines (82 loc) · 3.34 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"encoding/json"
"fmt"
"net/http"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"www.github.com/abit-tech/abit-backend/controllers"
"www.github.com/abit-tech/abit-backend/initializers"
"www.github.com/abit-tech/abit-backend/middleware"
)
var server *gin.Engine
func init() {
err := initializers.LoadConfig(".")
if err != nil {
panic("error in reading config")
}
initializers.ConnectDB()
initializers.SyncDatabase()
initializers.SetupGoogleOauth()
server = gin.Default()
prettyConf, _ := json.MarshalIndent(initializers.AppConf, "", "\t")
fmt.Printf("config object: %v\n", string(prettyConf))
}
func main() {
r := gin.Default()
r.GET("/healthchecker", func(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{"status": "success", "message": "server is up and running"})
})
corsConfig := cors.DefaultConfig()
corsConfig.AllowOrigins = []string{
"http://localhost:3000",
}
corsConfig.AllowCredentials = true
server.Use(cors.New(corsConfig))
router := server.Group("/api")
router.GET("/healthchecker", func(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{
"status": "success",
"message": "server is up and running",
})
})
router.POST("/waitlist", controllers.AddToWaitlist)
auth_router := router.Group("/auth")
auth_router.POST("/register", controllers.SignUpUser)
auth_router.POST("/login", controllers.SignInUser)
auth_router.GET("/logout", middleware.DeserializeUser(), controllers.LogoutUser)
google_router := router.Group("/google")
google_router.GET("/login/user", controllers.GoogleLoginForUser)
google_router.GET("/login/creator", controllers.GoogleLoginForCreator)
router.GET("/sessions/oauth/google", controllers.GoogleOAuth)
// router.GET("/sessions/oauth/google/creator", controllers.GoogleOAuthForCreator)
router.GET("/users/me", middleware.DeserializeUser(), controllers.GetMe)
video_router := router.Group("/video")
video_router.POST("/create", middleware.DeserializeUser(), controllers.CreateVideo)
video_router.POST("/fetch", middleware.DeserializeUser(), controllers.GetVideo)
video_router.POST("/update", middleware.DeserializeUser(), controllers.UpdateVideo)
video_router.POST("/delete", middleware.DeserializeUser(), controllers.DeleteVideo)
video_router.POST("/buytoken", middleware.DeserializeUser(), controllers.PurchaseToken)
dash_router := router.Group("/dash")
dash_router.POST("/user", middleware.DeserializeUser(), controllers.UserDash)
dash_router.POST("/creator", middleware.DeserializeUser(), controllers.CreatorDash)
// creator_router := router.Group("/creator")
// creator_router.POST("/profile", controllers.CreatorDummy)
// creator_router.POST("/videos", controllers.CreatorDummy)
router.StaticFS("/images", http.Dir("public"))
server.NoRoute(func(ctx *gin.Context) {
ctx.JSON(http.StatusNotFound, gin.H{
"status": "error",
"message": "route not found",
})
})
// r.POST("/signup", controllers.Signup)
// r.POST("/login", controllers.Login)
// r.POST("/validate", middleware.RequireAuth, controllers.Validate)
// auth_router := r.Group("/google")
// auth_router.GET("/register", controllers.GoogleLogin)
// auth_router.GET("/callback", controllers.GoogleCallback)
// // auth_router.POST("/login", controllers.GoogleSignInUser)
// // auth_router.GET("/logout", middleware.DeserializeUser(), controllers.GoogleLogoutUser)
server.Run(":" + "3000")
}