package main import ( "log" "os" "safetwitch-backend/extractor/chat" "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(), }) } } 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() { log.Println("Starting Safetwitch...") // check for env env := os.Getenv("URL") if env == "" { log.Fatalln("ENV Variable 'URL' is not present") } go chat.BeginTwitchChatConnection() router := gin.New() router.Use(gin.Recovery()) router.Use(ErrorHandler) routes.SetRoutes(router) router.NoRoute(notFoundHandler) log.Println("Safetwitch API running") router.Run() }