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

41 lines
647 B
Go

package main
import (
"fmt"
"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() {
router := gin.Default()
router.Use(ErrorHandler)
routes.SetRoutes(router)
router.NoRoute(notFoundHandler)
router.Run()
}