-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
43 lines (34 loc) · 970 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
package main
import (
"fmt"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/papadonut9/shawtyfy/dynamodb"
"github.com/papadonut9/shawtyfy/endpoint"
"github.com/papadonut9/shawtyfy/store"
)
// Main function
func main() {
route := gin.Default()
// Middleware to allow CORS
config := cors.DefaultConfig()
config.AllowOrigins = []string{"http://localhost:3000"}
config.AllowHeaders = []string{"Origin", "Content-Type"}
route.Use(cors.New(config))
// Calling setupRoutes to define endpoints
endpoint.SetupRoutes(route)
// initialize dynamodb service
dynamodb.InitializeDynamoDB()
// store initialization
store.InitializeStore()
// fetch context from middleware
route.Use(
func(ctx *gin.Context) {
go dynamodb.ListenForNewUrl(ctx, store.InitializeStore().GetRedisClient())
})
// start webserver
error := route.Run(":9808")
if error != nil {
panic(fmt.Sprintf("Failed to start web server: Error: %v", error))
}
}