初始
This commit is contained in:
30
internal/app/common/service/big_upload.go
Normal file
30
internal/app/common/service/big_upload.go
Normal file
@ -0,0 +1,30 @@
|
||||
// ================================================================================
|
||||
// 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 (
|
||||
"context"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/system"
|
||||
)
|
||||
|
||||
type IBigUpload interface {
|
||||
Upload(ctx context.Context, req *system.BigUploadReq) (res *system.BigUploadRes, err error)
|
||||
UploadCheck(ctx context.Context, req *system.BigUploadCheckReq) (res *system.BigUploadCheckRes, err error)
|
||||
UploadMerge(ctx context.Context, req *system.BigUploadMergeReq) (res *system.BigUploadRes, err error)
|
||||
}
|
||||
|
||||
var localBigUpload IBigUpload
|
||||
|
||||
func BigUpload() IBigUpload {
|
||||
if localBigUpload == nil {
|
||||
panic("implement not found for interface IBigUpload, forgot register?")
|
||||
}
|
||||
return localBigUpload
|
||||
}
|
||||
|
||||
func RegisterBigUpload(i IBigUpload) {
|
||||
localBigUpload = i
|
||||
}
|
||||
29
internal/app/common/service/cache.go
Normal file
29
internal/app/common/service/cache.go
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* @desc:缓存处理
|
||||
* @company:云南奇讯科技有限公司
|
||||
* @Author: yixiaohu
|
||||
* @Date: 2022/3/9 11:15
|
||||
*/
|
||||
|
||||
package service
|
||||
|
||||
import (
|
||||
"github.com/tiger1103/gfast-cache/cache"
|
||||
)
|
||||
|
||||
type ICache interface {
|
||||
cache.IGCache
|
||||
}
|
||||
|
||||
var c ICache
|
||||
|
||||
func Cache() ICache {
|
||||
if c == nil {
|
||||
panic("implement not found for interface ICache, forgot register?")
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func RegisterCache(che ICache) {
|
||||
c = che
|
||||
}
|
||||
28
internal/app/common/service/captcha.go
Normal file
28
internal/app/common/service/captcha.go
Normal file
@ -0,0 +1,28 @@
|
||||
// ================================================================================
|
||||
// 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 (
|
||||
"context"
|
||||
)
|
||||
|
||||
type ICaptcha interface {
|
||||
GetVerifyImgString(ctx context.Context) (idKeyC string, base64stringC string, err error)
|
||||
VerifyString(id, answer string) bool
|
||||
}
|
||||
|
||||
var localCaptcha ICaptcha
|
||||
|
||||
func Captcha() ICaptcha {
|
||||
if localCaptcha == nil {
|
||||
panic("implement not found for interface ICaptcha, forgot register?")
|
||||
}
|
||||
return localCaptcha
|
||||
}
|
||||
|
||||
func RegisterCaptcha(i ICaptcha) {
|
||||
localCaptcha = i
|
||||
}
|
||||
218
internal/app/common/service/casbin.go
Normal file
218
internal/app/common/service/casbin.go
Normal file
@ -0,0 +1,218 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/casbin/casbin/v2"
|
||||
"github.com/casbin/casbin/v2/model"
|
||||
"github.com/casbin/casbin/v2/persist"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/common/dao"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/common/model/entity"
|
||||
)
|
||||
|
||||
type cabinImpl struct{}
|
||||
|
||||
type adapterCasbin struct {
|
||||
Enforcer *casbin.SyncedEnforcer
|
||||
EnforcerErr error
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
var (
|
||||
cb = cabinImpl{}
|
||||
ac *adapterCasbin
|
||||
)
|
||||
|
||||
// CasbinEnforcer 获取adapter单例对象
|
||||
func CasbinEnforcer(ctx context.Context) (enforcer *casbin.SyncedEnforcer, err error) {
|
||||
ac = cb.newAdapter(ctx)
|
||||
enforcer = ac.Enforcer
|
||||
err = ac.EnforcerErr
|
||||
return
|
||||
}
|
||||
|
||||
// 初始化adapter操作
|
||||
func (s *cabinImpl) newAdapter(ctx context.Context) (a *adapterCasbin) {
|
||||
a = new(adapterCasbin)
|
||||
a.initPolicy(ctx)
|
||||
a.ctx = ctx
|
||||
return
|
||||
}
|
||||
|
||||
func (a *adapterCasbin) initPolicy(ctx context.Context) {
|
||||
// Because the DB is empty at first,
|
||||
// so we need to load the policy from the file adapter (.CSV) first.
|
||||
e, err := casbin.NewSyncedEnforcer(g.Cfg().MustGet(ctx, "casbin.modelFile").String(), a)
|
||||
if err != nil {
|
||||
a.EnforcerErr = err
|
||||
return
|
||||
}
|
||||
a.Enforcer = e
|
||||
}
|
||||
|
||||
// SavePolicy saves policy to database.
|
||||
func (a *adapterCasbin) SavePolicy(model model.Model) (err error) {
|
||||
err = a.dropTable()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = a.createTable()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for ptype, ast := range model["p"] {
|
||||
for _, rule := range ast.Policy {
|
||||
line := savePolicyLine(ptype, rule)
|
||||
_, err := dao.CasbinRule.Ctx(a.ctx).Data(line).Insert()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ptype, ast := range model["g"] {
|
||||
for _, rule := range ast.Policy {
|
||||
line := savePolicyLine(ptype, rule)
|
||||
_, err := dao.CasbinRule.Ctx(a.ctx).Data(line).Insert()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (a *adapterCasbin) dropTable() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (a *adapterCasbin) createTable() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// LoadPolicy loads policy from database.
|
||||
func (a *adapterCasbin) LoadPolicy(model model.Model) error {
|
||||
var lines []*entity.CasbinRule
|
||||
if err := dao.CasbinRule.Ctx(a.ctx).Scan(&lines); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, line := range lines {
|
||||
loadPolicyLine(line, model)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddPolicy adds a policy rule to the storage.
|
||||
func (a *adapterCasbin) AddPolicy(sec string, ptype string, rule []string) error {
|
||||
line := savePolicyLine(ptype, rule)
|
||||
_, err := dao.CasbinRule.Ctx(a.ctx).Data(line).Insert()
|
||||
return err
|
||||
}
|
||||
|
||||
// RemovePolicy removes a policy rule from the storage.
|
||||
func (a *adapterCasbin) RemovePolicy(sec string, ptype string, rule []string) error {
|
||||
line := savePolicyLine(ptype, rule)
|
||||
err := rawDelete(a, line)
|
||||
return err
|
||||
}
|
||||
|
||||
// RemoveFilteredPolicy removes policy rules that match the filter from the storage.
|
||||
func (a *adapterCasbin) RemoveFilteredPolicy(sec string, ptype string,
|
||||
fieldIndex int, fieldValues ...string,
|
||||
) error {
|
||||
line := &entity.CasbinRule{}
|
||||
line.Ptype = ptype
|
||||
if fieldIndex <= 0 && 0 < fieldIndex+len(fieldValues) {
|
||||
line.V0 = fieldValues[0-fieldIndex]
|
||||
}
|
||||
if fieldIndex <= 1 && 1 < fieldIndex+len(fieldValues) {
|
||||
line.V1 = fieldValues[1-fieldIndex]
|
||||
}
|
||||
if fieldIndex <= 2 && 2 < fieldIndex+len(fieldValues) {
|
||||
line.V2 = fieldValues[2-fieldIndex]
|
||||
}
|
||||
if fieldIndex <= 3 && 3 < fieldIndex+len(fieldValues) {
|
||||
line.V3 = fieldValues[3-fieldIndex]
|
||||
}
|
||||
if fieldIndex <= 4 && 4 < fieldIndex+len(fieldValues) {
|
||||
line.V4 = fieldValues[4-fieldIndex]
|
||||
}
|
||||
if fieldIndex <= 5 && 5 < fieldIndex+len(fieldValues) {
|
||||
line.V5 = fieldValues[5-fieldIndex]
|
||||
}
|
||||
err := rawDelete(a, line)
|
||||
return err
|
||||
}
|
||||
|
||||
func loadPolicyLine(line *entity.CasbinRule, model model.Model) {
|
||||
lineText := line.Ptype
|
||||
if line.V0 != "" {
|
||||
lineText += ", " + line.V0
|
||||
}
|
||||
if line.V1 != "" {
|
||||
lineText += ", " + line.V1
|
||||
}
|
||||
if line.V2 != "" {
|
||||
lineText += ", " + line.V2
|
||||
}
|
||||
if line.V3 != "" {
|
||||
lineText += ", " + line.V3
|
||||
}
|
||||
if line.V4 != "" {
|
||||
lineText += ", " + line.V4
|
||||
}
|
||||
if line.V5 != "" {
|
||||
lineText += ", " + line.V5
|
||||
}
|
||||
|
||||
persist.LoadPolicyLine(lineText, model)
|
||||
}
|
||||
|
||||
func savePolicyLine(ptype string, rule []string) *entity.CasbinRule {
|
||||
line := &entity.CasbinRule{}
|
||||
line.Ptype = ptype
|
||||
if len(rule) > 0 {
|
||||
line.V0 = rule[0]
|
||||
}
|
||||
if len(rule) > 1 {
|
||||
line.V1 = rule[1]
|
||||
}
|
||||
if len(rule) > 2 {
|
||||
line.V2 = rule[2]
|
||||
}
|
||||
if len(rule) > 3 {
|
||||
line.V3 = rule[3]
|
||||
}
|
||||
if len(rule) > 4 {
|
||||
line.V4 = rule[4]
|
||||
}
|
||||
if len(rule) > 5 {
|
||||
line.V5 = rule[5]
|
||||
}
|
||||
return line
|
||||
}
|
||||
|
||||
func rawDelete(a *adapterCasbin, line *entity.CasbinRule) error {
|
||||
db := dao.CasbinRule.Ctx(a.ctx).Where("ptype = ?", line.Ptype)
|
||||
if line.V0 != "" {
|
||||
db = db.Where("v0 = ?", line.V0)
|
||||
}
|
||||
if line.V1 != "" {
|
||||
db = db.Where("v1 = ?", line.V1)
|
||||
}
|
||||
if line.V2 != "" {
|
||||
db = db.Where("v2 = ?", line.V2)
|
||||
}
|
||||
if line.V3 != "" {
|
||||
db = db.Where("v3 = ?", line.V3)
|
||||
}
|
||||
if line.V4 != "" {
|
||||
db = db.Where("v4 = ?", line.V4)
|
||||
}
|
||||
if line.V5 != "" {
|
||||
db = db.Where("v5 = ?", line.V5)
|
||||
}
|
||||
_, err := db.Delete()
|
||||
return err
|
||||
}
|
||||
27
internal/app/common/service/middleware.go
Normal file
27
internal/app/common/service/middleware.go
Normal file
@ -0,0 +1,27 @@
|
||||
// ================================================================================
|
||||
// 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 (
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
type IMiddleware interface {
|
||||
MiddlewareCORS(r *ghttp.Request)
|
||||
}
|
||||
|
||||
var localMiddleware IMiddleware
|
||||
|
||||
func Middleware() IMiddleware {
|
||||
if localMiddleware == nil {
|
||||
panic("implement not found for interface IMiddleware, forgot register?")
|
||||
}
|
||||
return localMiddleware
|
||||
}
|
||||
|
||||
func RegisterMiddleware(i IMiddleware) {
|
||||
localMiddleware = i
|
||||
}
|
||||
37
internal/app/common/service/sys_config.go
Normal file
37
internal/app/common/service/sys_config.go
Normal file
@ -0,0 +1,37 @@
|
||||
// ================================================================================
|
||||
// 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 (
|
||||
"context"
|
||||
|
||||
"github.com/tiger1103/gfast/v3/api/v1/system"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/common/model/entity"
|
||||
)
|
||||
|
||||
type ISysConfig interface {
|
||||
List(ctx context.Context, req *system.ConfigSearchReq) (res *system.ConfigSearchRes, err error)
|
||||
Add(ctx context.Context, req *system.ConfigAddReq, userId uint64) (err error)
|
||||
CheckConfigKeyUnique(ctx context.Context, configKey string, configId ...int64) (err error)
|
||||
Get(ctx context.Context, id int) (res *system.ConfigGetRes, err error)
|
||||
Edit(ctx context.Context, req *system.ConfigEditReq, userId uint64) (err error)
|
||||
Delete(ctx context.Context, ids []int) (err error)
|
||||
GetConfigByKey(ctx context.Context, key string) (config *entity.SysConfig, err error)
|
||||
GetByKey(ctx context.Context, key string) (config *entity.SysConfig, err error)
|
||||
}
|
||||
|
||||
var localSysConfig ISysConfig
|
||||
|
||||
func SysConfig() ISysConfig {
|
||||
if localSysConfig == nil {
|
||||
panic("implement not found for interface ISysConfig, forgot register?")
|
||||
}
|
||||
return localSysConfig
|
||||
}
|
||||
|
||||
func RegisterSysConfig(i ISysConfig) {
|
||||
localSysConfig = i
|
||||
}
|
||||
34
internal/app/common/service/sys_dict_data.go
Normal file
34
internal/app/common/service/sys_dict_data.go
Normal file
@ -0,0 +1,34 @@
|
||||
// ================================================================================
|
||||
// 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 (
|
||||
"context"
|
||||
|
||||
"github.com/tiger1103/gfast/v3/api/v1/system"
|
||||
)
|
||||
|
||||
type ISysDictData interface {
|
||||
GetDictWithDataByType(ctx context.Context, req *system.GetDictReq) (dict *system.GetDictRes, err error)
|
||||
List(ctx context.Context, req *system.DictDataSearchReq) (res *system.DictDataSearchRes, err error)
|
||||
Add(ctx context.Context, req *system.DictDataAddReq, userId uint64) (err error)
|
||||
Get(ctx context.Context, dictCode uint) (res *system.DictDataGetRes, err error)
|
||||
Edit(ctx context.Context, req *system.DictDataEditReq, userId uint64) (err error)
|
||||
Delete(ctx context.Context, ids []int) (err error)
|
||||
}
|
||||
|
||||
var localSysDictData ISysDictData
|
||||
|
||||
func SysDictData() ISysDictData {
|
||||
if localSysDictData == nil {
|
||||
panic("implement not found for interface ISysDictData, forgot register?")
|
||||
}
|
||||
return localSysDictData
|
||||
}
|
||||
|
||||
func RegisterSysDictData(i ISysDictData) {
|
||||
localSysDictData = i
|
||||
}
|
||||
36
internal/app/common/service/sys_dict_type.go
Normal file
36
internal/app/common/service/sys_dict_type.go
Normal file
@ -0,0 +1,36 @@
|
||||
// ================================================================================
|
||||
// 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 (
|
||||
"context"
|
||||
|
||||
"github.com/tiger1103/gfast/v3/api/v1/system"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/common/model/entity"
|
||||
)
|
||||
|
||||
type ISysDictType interface {
|
||||
List(ctx context.Context, req *system.DictTypeSearchReq) (res *system.DictTypeSearchRes, err error)
|
||||
Add(ctx context.Context, req *system.DictTypeAddReq, userId uint64) (err error)
|
||||
Edit(ctx context.Context, req *system.DictTypeEditReq, userId uint64) (err error)
|
||||
Get(ctx context.Context, req *system.DictTypeGetReq) (dictType *entity.SysDictType, err error)
|
||||
ExistsDictType(ctx context.Context, dictType string, dictId ...int64) (err error)
|
||||
Delete(ctx context.Context, dictIds []int) (err error)
|
||||
GetAllDictType(ctx context.Context) (list []*entity.SysDictType, err error)
|
||||
}
|
||||
|
||||
var localSysDictType ISysDictType
|
||||
|
||||
func SysDictType() ISysDictType {
|
||||
if localSysDictType == nil {
|
||||
panic("implement not found for interface ISysDictType, forgot register?")
|
||||
}
|
||||
return localSysDictType
|
||||
}
|
||||
|
||||
func RegisterSysDictType(i ISysDictType) {
|
||||
localSysDictType = i
|
||||
}
|
||||
33
internal/app/common/service/upload.go
Normal file
33
internal/app/common/service/upload.go
Normal 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 (
|
||||
"context"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/system"
|
||||
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
type IUpload interface {
|
||||
UploadFiles(ctx context.Context, files []*ghttp.UploadFile, checkFileType string, source int) (result system.UploadMultipleRes, err error)
|
||||
UploadFile(ctx context.Context, file *ghttp.UploadFile, checkFileType string, source int) (result system.UploadResponse, err error)
|
||||
CheckSize(ctx context.Context, checkFileType string, file *ghttp.UploadFile) (err error)
|
||||
CheckType(ctx context.Context, checkFileType string, file *ghttp.UploadFile) (err error)
|
||||
}
|
||||
|
||||
var localUpload IUpload
|
||||
|
||||
func Upload() IUpload {
|
||||
if localUpload == nil {
|
||||
panic("implement not found for interface IUpload, forgot register?")
|
||||
}
|
||||
return localUpload
|
||||
}
|
||||
|
||||
func RegisterUpload(i IUpload) {
|
||||
localUpload = i
|
||||
}
|
||||
Reference in New Issue
Block a user