-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
127 lines (93 loc) · 2.99 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package main
import (
"blogs"
"contact"
"context"
"contribution"
"db"
"embed"
"jobs"
"leave"
"net/http"
"notification"
"os"
"post"
"sitemap"
"utils"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
ginadapter "github.com/awslabs/aws-lambda-go-api-proxy/gin"
"github.com/gin-contrib/cors"
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)
//go:embed templates/*.html
//go:embed templates/*.txt
var templateFS embed.FS
var router *gin.Engine
var ginLambda *ginadapter.GinLambda
func inLambda() bool {
if lambdaTaskRoot := os.Getenv("LAMBDA_TASK_ROOT"); lambdaTaskRoot != "" {
return true
}
return false
}
func LambdaHandler(ctx context.Context, req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
// If no name is provided in the HTTP request body, throw an error
return ginLambda.ProxyWithContext(ctx, req)
}
func setupRouter() *gin.Engine {
sqlDb := db.NewSql()
router := gin.Default()
router.Use(cors.New(corsConfig()))
router.Use(gzip.Gzip(gzip.DefaultCompression))
utilsRepo := utils.NewEmail()
contactRepo := contact.New(templateFS, utilsRepo)
jobsRepo := jobs.New(sqlDb, templateFS, utilsRepo)
sitemapRepo := sitemap.New(jobsRepo, templateFS)
leaveRepo := leave.New(templateFS, utilsRepo)
notificationRepo := notification.New(templateFS, utilsRepo)
lifePerksImagesRepo := jobs.NewLifePerksImages(sqlDb)
router.POST("/api/send-contact-mail", contactRepo.SendContactMail)
router.GET("/api/careers", jobsRepo.Careers)
router.GET("/api/careers/:unique_id", jobsRepo.CareerById)
router.POST("/api/send-jobs-applications", jobsRepo.SaveApplicationsData)
router.GET("/api/sitemap", sitemapRepo.GenerateSitemap)
router.GET("/api/blogs", blogs.Get)
router.GET("/api/github/stars", contribution.GetStargazers)
router.POST("/api/leave/new", leaveRepo.SendLeaveRequest)
router.POST("/api/leave/update", leaveRepo.SendUpdateLeaveMail)
router.POST("/api/invitation", notificationRepo.SendInvitationMail)
router.POST("/api/acceptence", notificationRepo.SendAcceptenceMail)
router.GET("/api/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "Pong",
})
})
router.GET("/api/lifeimages", lifePerksImagesRepo.LifeImages)
router.GET("/api/perksimages", lifePerksImagesRepo.PerksImages)
blogSqlDb := db.BlogDBInstance()
postRepo := post.New(blogSqlDb)
router.GET("/api/posts", postRepo.Get)
router.GET("/api/posts/:slug", postRepo.Show)
router.GET("/api/posts/tags/:slug", postRepo.GetPostsByTag)
router.GET("/api/posts/author/:username", postRepo.GetPostsByAuthor)
return router
}
func corsConfig() cors.Config {
defaultCors := cors.DefaultConfig()
defaultCors.AllowAllOrigins = true
return defaultCors
}
func main() {
router = setupRouter()
ginLambda = ginadapter.New(router)
if inLambda() {
log.Info("running aws lambda in aws")
lambda.Start(LambdaHandler)
} else {
log.Info("running aws lambda in local")
log.Fatal(http.ListenAndServe(":8082", router))
}
}