-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
61 lines (51 loc) · 1.43 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
package main
import (
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
"log"
"mygram/config"
_ "mygram/docs"
"mygram/repositories"
"mygram/routes"
"mygram/services"
"net/http"
"os"
)
// @title MyGram API
// @version 1.0
// @description Tempat untuk membuat user, social media, photo dan comment
// @contact.name Dandy Garda
// @contact.email dandygarda@gmail.com
// @host h8-mygram-production.up.railway.app
// @BasePath /
func main() {
godotenv.Load()
// Initialize gorm and postgres
err := config.InitGorm()
if err != nil {
panic(err)
}
repo := repositories.NewUserRepo(config.NewGorm.DB)
servUser := services.NewUserService(repo)
servSocialMedia := services.NewSocialMediaService(repo)
servPhoto := services.NewPhotoService(repo)
servComment := services.NewCommentService(repo)
newRouter := gin.New()
routes.UserRoutes(newRouter, servUser)
routes.SocialMediaRoutes(newRouter, servSocialMedia)
routes.PhotoRoutes(newRouter, servPhoto)
routes.CommentRoutes(newRouter, servComment)
newRouter.GET("/docs/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) // for swagger
newRouter.NoRoute(func(ctx *gin.Context) {
ctx.AbortWithStatusJSON(http.StatusNotFound, gin.H{
"message": "Route not found",
})
})
port := os.Getenv("PORT")
err = newRouter.Run(":" + port)
if err != nil {
log.Fatal(err)
}
}