根据gfv2 工程化改造,支持gf gen service

This commit is contained in:
JinMao 2022-10-23 15:19:39 +08:00
parent 8d67389bf6
commit e190609e35
60 changed files with 340 additions and 297 deletions

View File

@ -1,9 +1,9 @@
package user
import (
"Gf-Vben/app/service/middleware"
"Gf-Vben/app/service/user"
"Gf-Vben/app/util"
"Gf-Vben/internal/logic/user"
"Gf-Vben/internal/middleware"
"Gf-Vben/util"
"context"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"

9
api/v1/curd.go Normal file
View File

@ -0,0 +1,9 @@
package v1
import (
"github.com/gogf/gf/v2/frame/g"
)
type CurdReq struct {
g.Meta `path:"/curd" method:"post" summary:"Curd请求" tags:"Curd"`
}

View File

@ -1,70 +0,0 @@
package app
import (
casbin2 "Gf-Vben/app/service/casbin"
"fmt"
"github.com/casbin/casbin/v2"
"github.com/casbin/casbin/v2/model"
_ "github.com/gogf/gf/contrib/drivers/pgsql/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/os/glog"
adapter "github.com/jinmao88/gf-casbin"
"github.com/yitter/idgenerator-go/idgen"
)
// 应用初始化。
func init() {
//初始化路由
initRouter()
//初始化雪花ID
initIdGenerator()
//初始化Casbin
initCasbin()
}
func initIdGenerator() {
// 创建 IdGeneratorOptions 对象,请在构造函数中输入 WorkerId
var options = idgen.NewIdGeneratorOptions(1)
// options.WorkerIdBitLength = 10 // WorkerIdBitLength 默认值6支持的 WorkerId 最大值为2^6-1若 WorkerId 超过64可设置更大的 WorkerIdBitLength
// ...... 其它参数设置参考 IdGeneratorOptions 定义,一般来说,只要再设置 WorkerIdBitLength (决定 WorkerId 的最大值)。
// 保存参数(必须的操作,否则以上设置都不能生效):
idgen.SetIdGenerator(options)
}
func initCasbin() {
a, err := adapter.New(g.DB())
if err != nil {
glog.Error(gctx.New(), err)
return
}
modelFromString, err := model.NewModelFromString(`
[request_definition]
r = sub, dom, obj, act
[policy_definition]
p = sub, dom, obj, act
[role_definition]
g = _, _, _
[policy_effect]
e = some(where (p.eft == allow))
[matchers]
m = g(r.sub, p.sub, r.dom) && r.dom == p.dom && r.obj == p.obj && (r.act == p.act||p.act == "*")||p.sub == "admin"
`)
if err != nil {
glog.Error(gctx.New(), err)
return
}
casbin2.CE, err = casbin.NewEnforcer(modelFromString, a)
if err != nil {
glog.Error(gctx.New(), err)
return
}
domain := casbin2.CE.GetPermissionsForUserInDomain("user", "curd")
fmt.Println(domain)
glog.Printf(gctx.New(), "Cabin初始化成功")
}

View File

View File

@ -1,30 +0,0 @@
package casbin
import (
"github.com/casbin/casbin/v2"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
)
var CE *casbin.Enforcer
type Req struct {
Uid string `p:"uid"`
Domain string
Interface string `p:"i"`
Action string `p:"a"`
}
func (r *Req) Check() error {
g.Dump(r)
t, err := CE.Enforce(r.Uid, r.Domain, r.Interface, r.Action)
if err != nil {
return err
}
if !t {
return gerror.New("无此权限")
}
return nil
}

View File

@ -1,28 +0,0 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package dto
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// Router is the golang structure of table router for DAO operations like Where/Data.
type Router struct {
g.Meta `orm:"table:router, dto:true"`
Id interface{} //
Path interface{} //
Name interface{} //
Redirect interface{} //
Title interface{} //
Icon interface{} //
Component interface{} //
Parent interface{} //
OrderNo interface{} //
Status interface{} //
CreateAt *gtime.Time //
UpdateAt *gtime.Time //
DeleteAt *gtime.Time //
}

View File

@ -1,22 +0,0 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package dto
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// User is the golang structure of table user for DAO operations like Where/Data.
type User struct {
g.Meta `orm:"table:user, dto:true"`
Id interface{} //
Username interface{} //
Password interface{} //
Status interface{} //
CreateAt *gtime.Time //
UpdateAt *gtime.Time //
DeleteAt *gtime.Time //
}

View File

@ -1,23 +0,0 @@
package middleware
import (
"Gf-Vben/app/service/casbin"
"Gf-Vben/app/util"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/text/gstr"
)
func Casbin(r *ghttp.Request) {
var req casbin.Req
if err := r.Parse(&req); err != nil {
util.JsonExit(r, 1, "权限失效")
}
if gstr.Contains(r.RequestURI, "curd") {
req.Domain = "curd"
}
if err := req.Check(); err != nil {
util.JsonExit(r, 2, err.Error())
}
r.Middleware.Next()
}

View File

@ -15,17 +15,3 @@ database:
default:
link: "pgsql:user=gfvben password=JBprEMNHJ7Md host=47.116.71.73 port=5432 dbname=gfvben sslmode=disable"
debug: true
gfcli:
gen:
dao:
- link: "pgsql:user=gfvben password=JBprEMNHJ7Md host=47.116.71.73 port=5432 dbname=gfvben sslmode=disable"
path: "./app"
build:
name: "gf-vben"
arch: "arm"
system: "linux"
version: "v1.0.0"
output: "./bin"
extra: ""

10
go.mod
View File

@ -5,7 +5,7 @@ go 1.18
require (
github.com/casbin/casbin/v2 v2.44.0
github.com/gogf/gf-jwt/v2 v2.0.1
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.0.7-feature-clickhouse-driver-beta1
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.1.0
github.com/gogf/gf/v2 v2.0.6
github.com/jinmao88/gf-casbin v1.0.1
github.com/yitter/idgenerator-go v1.2.1
@ -18,7 +18,7 @@ require (
github.com/clbanning/mxj/v2 v2.5.5 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
@ -33,9 +33,9 @@ require (
github.com/mattn/go-runewidth v0.0.12 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/rivo/uniseg v0.1.0 // indirect
go.opentelemetry.io/otel v1.6.3 // indirect
go.opentelemetry.io/otel/sdk v1.6.3 // indirect
go.opentelemetry.io/otel/trace v1.6.3 // indirect
go.opentelemetry.io/otel v1.7.0 // indirect
go.opentelemetry.io/otel/sdk v1.7.0 // indirect
go.opentelemetry.io/otel/trace v1.7.0 // indirect
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 // indirect

13
hack/config.yaml Normal file
View File

@ -0,0 +1,13 @@
gfcli:
gen:
dao:
- link: "pgsql:user=gfvben password=JBprEMNHJ7Md host=47.116.71.73 port=5432 dbname=gfvben sslmode=disable"
build:
name: "gf-vben"
arch: "arm"
system: "linux"
version: "v1.0.0"
output: "./bin"
extra: ""

62
internal/boot/boot.go Normal file
View File

@ -0,0 +1,62 @@
package boot
import (
_ "Gf-Vben/internal/logic"
_ "Gf-Vben/internal/router"
_ "github.com/gogf/gf/contrib/drivers/pgsql/v2"
"github.com/yitter/idgenerator-go/idgen"
)
// 应用初始化。
func init() {
//初始化雪花ID
initIdGenerator()
//初始化Casbin
//initCasbin()
}
func initIdGenerator() {
// 创建 IdGeneratorOptions 对象,请在构造函数中输入 WorkerId
var options = idgen.NewIdGeneratorOptions(1)
// options.WorkerIdBitLength = 10 // WorkerIdBitLength 默认值6支持的 WorkerId 最大值为2^6-1若 WorkerId 超过64可设置更大的 WorkerIdBitLength
// ...... 其它参数设置参考 IdGeneratorOptions 定义,一般来说,只要再设置 WorkerIdBitLength (决定 WorkerId 的最大值)。
// 保存参数(必须的操作,否则以上设置都不能生效):
idgen.SetIdGenerator(options)
}
//func initCasbin() {
// a, err := adapter.New(g.DB())
// if err != nil {
// glog.Error(gctx.New(), err)
// return
// }
// modelFromString, err := model.NewModelFromString(`
// [request_definition]
// r = sub, dom, obj, act
//
// [policy_definition]
// p = sub, dom, obj, act
//
// [role_definition]
// g = _, _, _
//
// [policy_effect]
// e = some(where (p.eft == allow))
//
// [matchers]
// m = g(r.sub, p.sub, r.dom) && r.dom == p.dom && r.obj == p.obj && (r.act == p.act||p.act == "*")||p.sub == "admin"
// `)
// if err != nil {
// glog.Error(gctx.New(), err)
// return
// }
// casbin2.CE, err = casbin.NewEnforcer(modelFromString, a)
// if err != nil {
// glog.Error(gctx.New(), err)
// return
// }
// domain := casbin2.CE.GetPermissionsForUserInDomain("user", "curd")
// fmt.Println(domain)
// glog.Printf(gctx.New(), "Cabin初始化成功")
//}

View File

@ -1,6 +1,6 @@
package curd
import "Gf-Vben/app/model/entity"
import "Gf-Vben/internal/model/entity"
type Options interface {
entity.Permission | entity.Router

View File

@ -0,0 +1,26 @@
package controller
import (
"Gf-Vben/api/v1"
"Gf-Vben/internal/model"
"Gf-Vben/internal/service"
"Gf-Vben/util"
"context"
"github.com/gogf/gf/v2/frame/g"
)
var (
Curd = cCurd{}
)
type cCurd struct {
}
func (cCurd) Curd(ctx context.Context, req *v1.CurdReq) (res *util.JsonRes, err error) {
r := g.RequestFromCtx(ctx)
in := new(model.CurdReq)
if err := r.Parse(&in); err != nil {
return nil, err
}
return service.Curd().Curd(ctx, in)
}

View File

@ -5,7 +5,7 @@
package dao
import (
"Gf-Vben/app/service/internal/dao/internal"
"Gf-Vben/internal/dao/internal"
)
// internalCasbinRuleDao is internal type for wrapping internal DAO implements.

View File

@ -6,6 +6,7 @@ package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
@ -28,7 +29,7 @@ type CasbinRuleColumns struct {
V5 string //
}
// casbinRuleColumns holds the columns for table casbin_rule.
// casbinRuleColumns holds the columns for table casbin_rule.
var casbinRuleColumns = CasbinRuleColumns{
Ptype: "ptype",
V0: "v0",

View File

@ -6,6 +6,7 @@ package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
@ -20,7 +21,7 @@ type PermissionDao struct {
// PermissionColumns defines and stores column names for table permission.
type PermissionColumns struct {
Id string //
Parent string //
Parent string // 父级权限ID 0为权限域
Value string //
Desc string //
CreateAt string //
@ -30,7 +31,7 @@ type PermissionColumns struct {
Type string // 1 权限域 2 权限组 3 权限
}
// permissionColumns holds the columns for table permission.
// permissionColumns holds the columns for table permission.
var permissionColumns = PermissionColumns{
Id: "id",
Parent: "parent",

View File

@ -6,6 +6,7 @@ package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
@ -30,7 +31,7 @@ type RoleColumns struct {
Status string //
}
// roleColumns holds the columns for table role.
// roleColumns holds the columns for table role.
var roleColumns = RoleColumns{
Id: "id",
Name: "name",

View File

@ -6,6 +6,7 @@ package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
@ -35,7 +36,7 @@ type RouterColumns struct {
Id string //
}
// routerColumns holds the columns for table router.
// routerColumns holds the columns for table router.
var routerColumns = RouterColumns{
Path: "path",
Name: "name",

View File

@ -6,6 +6,7 @@ package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
@ -28,7 +29,7 @@ type UserColumns struct {
DeleteAt string //
}
// userColumns holds the columns for table user.
// userColumns holds the columns for table user.
var userColumns = UserColumns{
Id: "id",
Username: "username",

View File

@ -5,7 +5,7 @@
package dao
import (
"Gf-Vben/app/service/internal/dao/internal"
"Gf-Vben/internal/dao/internal"
)
// internalPermissionDao is internal type for wrapping internal DAO implements.

View File

@ -5,7 +5,7 @@
package dao
import (
"Gf-Vben/app/service/internal/dao/internal"
"Gf-Vben/internal/dao/internal"
)
// internalRoleDao is internal type for wrapping internal DAO implements.

View File

@ -5,13 +5,16 @@
package dao
import (
"Gf-Vben/app/service/internal/dao/internal"
"Gf-Vben/internal/dao/internal"
)
// internalRouterDao is internal type for wrapping internal DAO implements.
type internalRouterDao = *internal.RouterDao
// routerDao is the data access object for table router.
// You can define custom methods on it to extend its functionality as you wish.
type routerDao struct {
*internal.RouterDao
internalRouterDao
}
var (

View File

@ -5,13 +5,16 @@
package dao
import (
"Gf-Vben/app/service/internal/dao/internal"
"Gf-Vben/internal/dao/internal"
)
// internalUserDao is internal type for wrapping internal DAO implements.
type internalUserDao = *internal.UserDao
// userDao is the data access object for table user.
// You can define custom methods on it to extend its functionality as you wish.
type userDao struct {
*internal.UserDao
internalUserDao
}
var (

View File

@ -1,30 +1,34 @@
package curd
import (
"Gf-Vben/app/service/curd"
"Gf-Vben/app/service/permission"
"Gf-Vben/app/service/role"
"Gf-Vben/app/service/router"
"Gf-Vben/app/service/user"
"Gf-Vben/app/util"
"Gf-Vben/internal/const/curd"
"Gf-Vben/internal/logic/permission"
"Gf-Vben/internal/logic/role"
"Gf-Vben/internal/logic/router"
"Gf-Vben/internal/logic/user"
"Gf-Vben/internal/model"
"Gf-Vben/internal/service"
"Gf-Vben/util"
"context"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
)
type Api struct {
type sCurd struct {
}
type CurdReq struct {
g.Meta `path:"/curd" method:"post" summary:"Curd请求" tags:"Curd"`
Interface string `p:"i" v:"required"`
Action string `p:"a" v:"required"`
func init() {
service.RegisterCurd(New())
}
func New() *sCurd {
return &sCurd{}
}
func (Api) Curd(ctx context.Context, req *CurdReq) (res *util.JsonRes, err error) {
func (s *sCurd) Curd(ctx context.Context, r *model.CurdReq) (res *util.JsonRes, err error) {
var cu curd.Curd
res = new(util.JsonRes)
switch req.Interface {
switch r.Interface {
case "user":
cu = new(user.Req)
case "router":
@ -40,7 +44,7 @@ func (Api) Curd(ctx context.Context, req *CurdReq) (res *util.JsonRes, err error
if err = g.RequestFromCtx(ctx).Parse(cu); err != nil {
return nil, gerror.NewCode(util.Code(2), err.Error())
}
switch req.Action {
switch r.Action {
case "list":
res.Data, err = cu.List()
case "tree":
@ -60,5 +64,4 @@ func (Api) Curd(ctx context.Context, req *CurdReq) (res *util.JsonRes, err error
err = gerror.NewCode(util.Code(3), "接口参数错误")
}
return
}

View File

@ -1,46 +1,39 @@
package example
import (
"Gf-Vben/app/model/entity"
"Gf-Vben/app/service/curd"
"Gf-Vben/app/service/internal/dao"
"Gf-Vben/internal/const/curd"
"Gf-Vben/internal/dao"
"Gf-Vben/internal/model/entity"
"context"
"github.com/gogf/gf/v2/frame/g"
)
type Req struct {
Page int `p:"page"`
PageSize int `p:"page_size"`
Ctx context.Context `p:"ctx"`
curd.Pagination
Ctx context.Context `p:"ctx"`
Query
}
type Query struct {
Id int `p:"id"`
User int `p:"user"`
Name string `p:"name"`
NameEn string `p:"name_en"`
Desc string `p:"desc"`
DescEn string `p:"desc_en"`
Icon string `p:"icon"`
Href string `p:"href"`
Sort int `p:"sort"`
Type int `p:"type"`
Status string `p:"status"`
Id int `p:"id"`
}
func (r *Req) SetCtx(ctx context.Context) {
r.Ctx = ctx
}
func (r *Req) List() (*curd.List, error) {
res := make([]entity.User, 0)
m := dao.User.Ctx(r.Ctx)
count, err := m.Count()
if err != nil {
return nil, err
}
if err := m.Page(r.Page, r.PageSize).Scan(res); err != nil {
all, err := m.Page(r.Page, r.PageSize).All()
if err != nil {
return nil, err
}
return &curd.List{
Items: res,
Items: all,
Total: count,
Page: r.Page,
PageSize: r.PageSize,

14
internal/logic/logic.go Normal file
View File

@ -0,0 +1,14 @@
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package logic
import (
_ "Gf-Vben/internal/logic/curd"
_ "Gf-Vben/internal/logic/example"
_ "Gf-Vben/internal/logic/permission"
_ "Gf-Vben/internal/logic/role"
_ "Gf-Vben/internal/logic/router"
_ "Gf-Vben/internal/logic/user"
)

View File

@ -1,9 +1,9 @@
package permission
import (
"Gf-Vben/app/model/entity"
"Gf-Vben/app/service/curd"
"Gf-Vben/app/service/internal/dao"
"Gf-Vben/internal/const/curd"
"Gf-Vben/internal/dao"
"Gf-Vben/internal/model/entity"
"context"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"

View File

@ -1,9 +1,9 @@
package role
import (
"Gf-Vben/app/model/entity"
"Gf-Vben/app/service/curd"
"Gf-Vben/app/service/internal/dao"
"Gf-Vben/internal/const/curd"
"Gf-Vben/internal/dao"
"Gf-Vben/internal/model/entity"
"context"
"github.com/gogf/gf/v2/frame/g"
)

View File

@ -1,9 +1,9 @@
package router
import (
"Gf-Vben/app/model/entity"
"Gf-Vben/app/service/curd"
"Gf-Vben/app/service/internal/dao"
"Gf-Vben/internal/const/curd"
"Gf-Vben/internal/dao"
"Gf-Vben/internal/model/entity"
"context"
"github.com/gogf/gf/v2/frame/g"
)

View File

@ -1,17 +1,15 @@
package user
import (
"Gf-Vben/app/model/entity"
"Gf-Vben/app/service/curd"
"Gf-Vben/app/service/internal/dao"
"Gf-Vben/internal/const/curd"
"Gf-Vben/internal/dao"
"context"
"github.com/gogf/gf/v2/frame/g"
)
type Req struct {
Ctx context.Context
Page int `p:"page"`
PageSize int `p:"page_size"`
Ctx context.Context
curd.Pagination
Query
}
type Query struct {
@ -25,13 +23,19 @@ func (r *Req) SetCtx(ctx context.Context) {
}
func (r *Req) List() (*curd.List, error) {
res := make([]entity.User, 0)
if err := dao.User.Ctx(r.Ctx).Scan(&res); err != nil {
m := dao.User.Ctx(r.Ctx)
count, err := m.Count()
if err != nil {
return nil, err
}
all, err := m.FieldsEx(dao.User.Columns().Password).All()
if err != nil {
return nil, err
}
return &curd.List{
Items: res,
Total: len(res),
Items: all,
Total: count,
Page: r.Page,
PageSize: r.PageSize,
}, nil

View File

@ -1,9 +1,8 @@
package user
import (
"Gf-Vben/app/model/entity"
"Gf-Vben/app/service/casbin"
"Gf-Vben/app/service/internal/dao"
"Gf-Vben/internal/dao"
"Gf-Vben/internal/model/entity"
"context"
"github.com/gogf/gf/v2/crypto/gmd5"
"github.com/gogf/gf/v2/errors/gerror"
@ -81,12 +80,12 @@ type MenuReq struct {
}
func (r *MenuReq) Menu() ([]*Menu, error) {
casbin.CE.LoadPolicy()
var p []string
permissions := casbin.CE.GetPermissionsForUserInDomain(r.Uid, "menu")
for _, permission := range permissions {
p = append(p, permission[2])
}
//casbin.CE.LoadPolicy()
//var p []string
//permissions := casbin.CE.GetPermissionsForUserInDomain(r.Uid, "menu")
//for _, permission := range permissions {
// p = append(p, permission[2])
//}
var routers []*Menu
if err := dao.Router.Ctx(r.Ctx).Where(dao.Router.Columns().Status, 1).Order(dao.Router.Columns().Parent).Scan(&routers); err != nil {
return nil, err

View File

@ -0,0 +1,16 @@
package middleware
//func Casbin(r *ghttp.Request) {
// var req casbin.Req
// if err := r.Parse(&req); err != nil {
// util.JsonExit(r, 1, "权限失效")
// }
// if gstr.Contains(r.RequestURI, "curd") {
// req.Domain = "curd"
// }
// if err := req.Check(); err != nil {
// util.JsonExit(r, 2, err.Error())
// }
// r.Middleware.Next()
//
//}

View File

@ -1,9 +1,9 @@
package middleware
import (
"Gf-Vben/app/model/entity"
"Gf-Vben/app/service/internal/dao"
"Gf-Vben/app/service/user"
"Gf-Vben/internal/dao"
"Gf-Vben/internal/logic/user"
"Gf-Vben/internal/model/entity"
"context"
jwt "github.com/gogf/gf-jwt/v2"
"github.com/gogf/gf/v2/crypto/gmd5"

View File

@ -1,6 +1,6 @@
package middleware
//初始化中间件
// 初始化中间件
func init() {
//初始化Jwt
initJwt()

View File

@ -13,7 +13,7 @@ import (
type Permission struct {
g.Meta `orm:"table:permission, do:true"`
Id interface{} //
Parent interface{} //
Parent interface{} // 父级权限ID 0为权限域
Value interface{} //
Desc interface{} //
CreateAt *gtime.Time //

View File

@ -19,6 +19,6 @@ type Role struct {
DeleteAt *gtime.Time //
Value interface{} //
Desc interface{} //
Permission interface{} //
Permission []int //
Status interface{} //
}

View File

@ -10,13 +10,13 @@ import (
// Permission is the golang structure for table permission.
type Permission struct {
Id int64 `json:"id" ` //
Parent int64 `json:"parent" ` //
Id int `json:"id" ` //
Parent int `json:"parent" ` // 父级权限ID 0为权限域
Value string `json:"value" ` //
Desc string `json:"desc" ` //
CreateAt *gtime.Time `json:"createAt" ` //
UpdateAt *gtime.Time `json:"updateAt" ` //
DeleteAt *gtime.Time `json:"deleteAt" ` //
Name string `json:"name" ` //
Type int64 `json:"type" ` // 1 权限域 2 权限组 3 权限
Type int `json:"type" ` // 1 权限域 2 权限组 3 权限
}

View File

@ -10,13 +10,13 @@ import (
// Role is the golang structure for table role.
type Role struct {
Id int64 `json:"id" ` //
Id int `json:"id" ` //
Name string `json:"name" ` //
CreateAt *gtime.Time `json:"createAt" ` //
UpdateAt *gtime.Time `json:"updateAt" ` //
DeleteAt *gtime.Time `json:"deleteAt" ` //
Value string `json:"value" ` //
Desc string `json:"desc" ` //
Permission int `json:"permission" ` //
Status int64 `json:"status" ` //
Permission []int `json:"permission" ` //
Status int `json:"status" ` //
}

View File

@ -16,12 +16,12 @@ type Router struct {
Title string `json:"title" ` //
Icon string `json:"icon" ` //
Component string `json:"component" ` //
Parent int64 `json:"parent" ` //
OrderNo int64 `json:"orderNo" ` //
Parent int `json:"parent" ` //
OrderNo int `json:"orderNo" ` //
Status int `json:"status" ` //
CreateAt *gtime.Time `json:"createAt" ` //
UpdateAt *gtime.Time `json:"updateAt" ` //
DeleteAt *gtime.Time `json:"deleteAt" ` //
Permission string `json:"permission" ` //
Id int64 `json:"id" ` //
Id int `json:"id" ` //
}

View File

@ -10,7 +10,7 @@ import (
// User is the golang structure for table user.
type User struct {
Id int64 `json:"id" ` //
Id int `json:"id" ` //
Username string `json:"username" ` //
Password string `json:"password" ` //
Status int `json:"status" ` //

6
internal/model/in.go Normal file
View File

@ -0,0 +1,6 @@
package model
type CurdReq struct {
Interface string `p:"i" v:"required"`
Action string `p:"a" v:"required"`
}

View File

@ -1,10 +1,10 @@
package app
package router
import (
"Gf-Vben/app/api/curd"
"Gf-Vben/app/api/user"
"Gf-Vben/app/service/middleware"
"Gf-Vben/app/util"
"Gf-Vben/api/user"
"Gf-Vben/internal/controller"
"Gf-Vben/internal/middleware"
"Gf-Vben/util"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
)
@ -12,7 +12,7 @@ import (
// 你可以将路由注册放到一个文件中管理,
// 也可以按照模块拆分到不同的文件中管理,
// 但统一都放到router目录下。
func initRouter() {
func init() {
s := g.Server()
s.Use(util.ResponseHandler, middleware.CORS)
@ -30,10 +30,10 @@ func initRouter() {
new(user.Api2),
)
})
group.Middleware(middleware.Casbin)
//group.Middleware(middleware.Casbin)
group.Bind(
new(curd.Api),
controller.Curd,
)
})

33
internal/service/curd.go Normal file
View File

@ -0,0 +1,33 @@
// ================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// You can delete these comments if you wish manually maintain this interface file.
// ================================================================================
package service
import (
"Gf-Vben/internal/model"
"Gf-Vben/util"
"context"
)
type (
ICurd interface {
Curd(ctx context.Context, r *model.CurdReq) (res *util.JsonRes, err error)
}
)
var (
localCurd ICurd
)
func Curd() ICurd {
if localCurd == nil {
panic("implement not found for interface ICurd, forgot register?")
}
return localCurd
}
func RegisterCurd(i ICurd) {
localCurd = i
}

View File

@ -0,0 +1,8 @@
// ================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// You can delete these comments if you wish manually maintain this interface file.
// ================================================================================
package service
type ()

View File

@ -0,0 +1,8 @@
// ================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// You can delete these comments if you wish manually maintain this interface file.
// ================================================================================
package service
type ()

8
internal/service/role.go Normal file
View File

@ -0,0 +1,8 @@
// ================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// You can delete these comments if you wish manually maintain this interface file.
// ================================================================================
package service
type ()

View File

@ -0,0 +1,8 @@
// ================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// You can delete these comments if you wish manually maintain this interface file.
// ================================================================================
package service
type ()

8
internal/service/user.go Normal file
View File

@ -0,0 +1,8 @@
// ================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// You can delete these comments if you wish manually maintain this interface file.
// ================================================================================
package service
type ()

View File

@ -1,7 +1,8 @@
package main
import (
_ "Gf-Vben/app"
_ "Gf-Vben/internal/boot"
"github.com/gogf/gf/v2/frame/g"
)