feat(admin): add comprehensive admin management system
- Add admin handlers and services for users, posts, comments, groups, and dashboard - Implement role permission management with ability to view and update permissions - Add database seeding for roles and Casbin permission policies - Upgrade Casbin from v2 to v3 with GORM adapter for persistent policy storage - Add admin-specific repository methods with filtering and pagination - Register new admin API routes under /api/v1/admin/*
This commit is contained in:
@@ -13,7 +13,8 @@ import (
|
||||
"carrot_bbs/internal/repository"
|
||||
"carrot_bbs/internal/service"
|
||||
|
||||
"github.com/casbin/casbin/v2"
|
||||
"github.com/casbin/casbin/v3"
|
||||
gormadapter "github.com/casbin/gorm-adapter/v3"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -64,8 +65,14 @@ func main() {
|
||||
log.Printf("[WARNING] Failed to init casbin policies: %v", err)
|
||||
}
|
||||
|
||||
// 创建 GORM 适配器
|
||||
adapter, err := gormadapter.NewAdapterByDB(db)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create GORM adapter: %v", err)
|
||||
}
|
||||
|
||||
// 创建 Casbin Enforcer
|
||||
enforcer, err := casbin.NewEnforcer(cfg.Casbin.ModelPath)
|
||||
enforcer, err := casbin.NewEnforcer(cfg.Casbin.ModelPath, adapter)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create enforcer: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user