package casbin

import (
	"fmt"
	"github.com/casbin/casbin/v2"
	gormadapter "github.com/casbin/gorm-adapter/v3"
	"log"
)

var Enforcer *casbin.Enforcer

func Setup() {
	var err error
	a, _ := gormadapter.NewAdapter("mysql", "root:fVkWkJZoOQcpunqC@tcp(172.16.101.45:3306)/pc_manage", true)
	Enforcer, err = casbin.NewEnforcer("./conf/model.conf", a)
	if err != nil {
		fmt.Println("casbin.Setup, fail to parse 'conf/model.conf': %v", err)
		log.Fatalf("casbin.Setup, fail to parse 'conf/model.conf': %v", err)
	}

	fmt.Println("casbin ok")
	// 日志记录
	Enforcer.EnableLog(true)
}
