0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch-backend.git synced 2024-12-22 13:13:00 -05:00
safetwitch-backend/main.go

50 lines
781 B
Go
Raw Normal View History

2023-05-18 09:17:08 -05:00
package main
import (
"fmt"
2023-05-22 09:27:44 -05:00
"os"
2023-05-18 09:17:08 -05:00
"safetwitch-backend/routes"
"strings"
"github.com/gin-gonic/gin"
)
func ErrorHandler(c *gin.Context) {
c.Next()
err := c.Errors.Last()
if err != nil {
c.JSON(500, gin.H{
"status": "error",
"message": err.Error(),
})
}
fmt.Println(err)
}
2023-05-18 09:17:08 -05:00
func notFoundHandler(context *gin.Context) {
message := []string{"path", context.Request.URL.Path, "was not found."}
context.JSON(404, gin.H{
"status": "error",
"message": strings.Join(message, " "),
})
}
func main() {
2023-05-22 09:27:44 -05:00
// check for env
env := os.Getenv("URL")
if env == "" {
fmt.Println("ENV Variable 'URL' is not present")
os.Exit(10)
}
2023-05-18 09:17:08 -05:00
router := gin.Default()
router.Use(ErrorHandler)
2023-05-18 09:17:08 -05:00
routes.SetRoutes(router)
router.NoRoute(notFoundHandler)
router.Run()
}