func (a *Config) CheckPermission(c echo.Context) (bool, error) {
	user, err := a.GetUserName(c)
	if err != nil {
		return false, nil
	}
	method := c.Request().Method
	path := c.Request().URL.Path
	return a.Enforcer.Enforce(user, path, method)
}
CheckPermission checks the user/method/path combination from the request.
Returns true (permission granted) or false (permission forbidden)
package casbin
import (
	"net/http"
	"github.com/casbin/casbin/v2"
	"github.com/labstack/echo/v4"
	"github.com/labstack/echo/v4/middleware"
)
type (
	Config struct {
		Skipper middleware.Skipper
		Enforcer *casbin.Enforcer
		UserGetter func(c echo.Context) (string, error)
	}
)
var (
	DefaultConfig = Config{
		Skipper: middleware.DefaultSkipper,
		UserGetter: func(c echo.Context) (string, error) {
			username, _, _ := c.Request().BasicAuth()
			return username, nil
		},
	}
)
func Middleware(ce *casbin.Enforcer) echo.MiddlewareFunc {
	c := DefaultConfig
	c.Enforcer = ce
	return MiddlewareWithConfig(c)
}
func MiddlewareWithConfig(config Config) echo.MiddlewareFunc {
	if config.Skipper == nil {
		config.Skipper = DefaultConfig.Skipper
	}
	return func(next echo.HandlerFunc) echo.HandlerFunc {
		return func(c echo.Context) error {
			if config.Skipper(c) {
				return next(c)
			}
			if pass, err := config.CheckPermission(c); err == nil && pass {
				return next(c)
			} else if err != nil {
				return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
			}
			return echo.ErrForbidden
		}
	}
}
func (a *Config) GetUserName(c echo.Context) (string, error) {
	username, err := a.UserGetter(c)
	return username, err
}