I wanted to create a route group wherein I can only passed the "repo.GetUsers" only and not create an if statement, for simplicity.
I'm practicing a crud application and if someone can help me solve this, then it would be a really big help.
package repository
import (
"net/http"
"github.com/gin-gonic/gin"
)
func (repo *Repository) SetupRoutes(app *gin.Engine) {
api := app.Group("/api")
{
api.GET("/users", func(ctx *gin.Context) {
err := repo.GetUsers(ctx)
if err != nil {
// Handle the error, if needed
ctx.IndentedJSON(http.StatusInternalServerError, gin.H{
"data": err.Error(),
"message": "failed to get users",
"success": false,
})
return
}
})
}
}
The code above is the code that I used and it works, but I wanted it to only become like this:
func (repo *Repository) SetupRoutes(app *gin.Engine) {
api := app.Group("/api")
{
api.GET("/users", repo.GetUsers)
}
}