azote-backend/main.go

56 lines
1.2 KiB
Go
Raw Normal View History

2024-01-16 00:36:49 +01:00
package main
import (
"azote-backend/api"
"azote-backend/controllers"
"azote-backend/initializers"
2024-01-18 23:45:06 +01:00
"azote-backend/middleware"
2024-01-16 00:36:49 +01:00
"github.com/gin-gonic/gin"
"log"
"os"
)
2024-02-28 09:13:08 +01:00
var currentMode string
2024-01-16 00:36:49 +01:00
func init() {
initializers.LoadEnv()
2024-02-28 09:13:08 +01:00
currentMode = os.Getenv("GIN_MODE")
if currentMode == "debug" {
initializers.CreateAssetsFolder(initializers.DebugBasePath)
} else {
initializers.CreateAssetsFolder(initializers.ReleaseBasePath)
}
2024-01-16 00:36:49 +01:00
initializers.ConnectToDB()
}
func main() {
gin.SetMode(os.Getenv("GIN_MODE"))
api.CreateRouter()
// Auth
api.Api.POST("/signup", controllers.Signup)
api.Api.POST("/login", controllers.Login)
api.Api.GET("/validate", middleware.RequireAuth, controllers.ValidateToken)
2024-01-16 00:36:49 +01:00
// Users
api.Api.GET("/users", controllers.GetUsers)
api.Api.GET("/users/:id", controllers.GetUserById)
// Files
2024-02-28 09:13:08 +01:00
if currentMode == "debug" {
api.Router.Static("assets", initializers.DebugBasePath+"/images")
} else {
api.Router.Static("assets", initializers.ReleaseBasePath+"/images")
}
2024-01-16 00:36:49 +01:00
2024-02-28 09:13:08 +01:00
// Posts
2024-01-18 23:45:06 +01:00
api.Api.POST("/posts", middleware.RequireAuth, controllers.CreatePost)
2024-01-16 00:36:49 +01:00
// Starting
err := api.Router.Run()
if err != nil {
log.Fatal("Router could not be created!\n" + err.Error())
}
}