package main import ( "fmt" "os" "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) } 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() { // check for env env := os.Getenv("URL") if env == "" { fmt.Println("ENV Variable 'URL' is not present") os.Exit(10) } router := gin.Default() router.Use(ErrorHandler) routes.SetRoutes(router) router.NoRoute(notFoundHandler) router.Run() }