mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-02 07:20:24 +08:00
refactor: interface{} -> any
feat: 新增外链菜单
This commit is contained in:
@@ -29,7 +29,7 @@
|
||||
"sql-formatter": "^12.1.2",
|
||||
"vue": "^3.3.4",
|
||||
"vue-clipboard3": "^1.0.1",
|
||||
"vue-router": "^4.2.1",
|
||||
"vue-router": "^4.2.2",
|
||||
"xterm": "^5.1.0",
|
||||
"xterm-addon-fit": "^0.7.0"
|
||||
},
|
||||
@@ -49,7 +49,7 @@
|
||||
"sass": "^1.62.0",
|
||||
"sass-loader": "^13.2.0",
|
||||
"typescript": "^5.0.2",
|
||||
"vite": "^4.3.8",
|
||||
"vite": "^4.3.9",
|
||||
"vue-eslint-parser": "^9.1.1"
|
||||
},
|
||||
"browserslist": [
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
if (el) columnsAsideOffsetTopRefs[k] = el;
|
||||
}
|
||||
" :class="{ 'layout-columns-active': state.liIndex === k }" :title="v.meta.title">
|
||||
<div class="layout-columns-aside-li-box" v-if="!v.meta.link || (v.meta.link && v.meta.isIframe)">
|
||||
<div class="layout-columns-aside-li-box" v-if="!v.meta.link || (v.meta.link && v.meta.linkType == 1)">
|
||||
<i :class="v.meta.icon"></i>
|
||||
<div class="layout-columns-aside-li-box-title font12">
|
||||
{{ v.meta.title && v.meta.title.length >= 4 ? v.meta.title.substr(0, 4) : v.meta.title }}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
<template>
|
||||
<el-main class="layout-main">
|
||||
<el-scrollbar class="layout-scrollbar" ref="layoutScrollbarRef"
|
||||
v-show="!state.currentRouteMeta.link && !state.currentRouteMeta.isIframe"
|
||||
v-show="!state.currentRouteMeta.link && state.currentRouteMeta.linkType != 1"
|
||||
:style="{ minHeight: `calc(100vh - ${state.headerHeight}` }">
|
||||
<LayoutParentView />
|
||||
<Footer v-if="themeConfig.isFooter" />
|
||||
</el-scrollbar>
|
||||
<Link :style="{ height: `calc(100vh - ${state.headerHeight}` }" :meta="state.currentRouteMeta"
|
||||
v-if="state.currentRouteMeta.link && !state.currentRouteMeta.isIframe" />
|
||||
v-if="state.currentRouteMeta.link && state.currentRouteMeta.linkType == 2" />
|
||||
<Iframes :style="{ height: `calc(100vh - ${state.headerHeight}` }" :meta="state.currentRouteMeta"
|
||||
v-if="state.currentRouteMeta.link && state.currentRouteMeta.isIframe && state.isShowLink"
|
||||
v-if="state.currentRouteMeta.link && state.currentRouteMeta.linkType == 1 && state.isShowLink"
|
||||
@getCurrentRouteMeta="onGetCurrentRouteMeta" />
|
||||
</el-main>
|
||||
</template>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<template>
|
||||
<div class="layout-footer mt15" v-show="isDelayFooter">
|
||||
<div class="layout-footer-warp">
|
||||
<div>vue-next-admin,Made by lyt with ❤️</div>
|
||||
<div class="mt5">mayfly</div>
|
||||
<div>Made by mayfly with ❤️</div>
|
||||
<div class="mt5">mayfly-go</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -87,7 +87,7 @@ const getRoutes = (routes: any) => {
|
||||
// 当前菜单选中时
|
||||
const onHandleSelect = (item: any) => {
|
||||
let { path, redirect } = item;
|
||||
if (item.meta.link && !item.meta.isIframe) window.open(item.meta.link);
|
||||
if (item.meta.link && item.meta.linkType == 2) window.open(item.meta.link);
|
||||
else if (redirect) router.push(redirect);
|
||||
else router.push(path);
|
||||
closeSearch();
|
||||
|
||||
@@ -38,7 +38,7 @@ import { useRoute, useRouter, onBeforeRouteUpdate } from 'vue-router';
|
||||
import screenfull from 'screenfull';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useThemeConfig } from '@/store/themeConfig';
|
||||
import { getSession, setSession, removeSession } from '@/common/utils/storage.ts';
|
||||
import { getSession, setSession, removeSession } from '@/common/utils/storage';
|
||||
import mittBus from '@/common/utils/mitt';
|
||||
import Sortable from 'sortablejs';
|
||||
import Contextmenu from '@/views/layout/navBars/tagsView/contextmenu.vue';
|
||||
@@ -99,13 +99,14 @@ const addTagsView = (path: string, to: any = null) => {
|
||||
if (!to) {
|
||||
to = route;
|
||||
}
|
||||
|
||||
path = decodeURI(path);
|
||||
for (let tv of state.tagsViewList) {
|
||||
if (tv.fullPath === path) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const tagView = { ...to }
|
||||
// 防止Converting circular structure to JSON错误
|
||||
tagView.matched = null;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<SubItem :chil="val.children" />
|
||||
</el-sub-menu>
|
||||
<el-menu-item :index="val.path" :key="val?.path" v-else>
|
||||
<template #title v-if="!val.meta.link || (val.meta.link && val.meta.isIframe)">
|
||||
<template #title v-if="!val.meta.link || (val.meta.link && val.meta.linkType == 1)">
|
||||
<SvgIcon :name="val.meta.icon"/>
|
||||
{{ val.meta.title }}
|
||||
</template>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<sub-item :chil="val.children" />
|
||||
</el-sub-menu>
|
||||
<el-menu-item :index="val.path" :key="val?.path" v-else>
|
||||
<template v-if="!val.meta.link || (val.meta.link && val.meta.isIframe)">
|
||||
<template v-if="!val.meta.link || (val.meta.link && val.meta.linkType == 1)">
|
||||
<SvgIcon :name="val.meta.icon"/>
|
||||
<span>{{ val.meta.title }}</span>
|
||||
</template>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
</el-sub-menu>
|
||||
<el-menu-item :index="val.path" :key="val?.path" v-else>
|
||||
<SvgIcon :name="val.meta.icon"/>
|
||||
<template #title v-if="!val.meta.link || (val.meta.link && val.meta.isIframe)">
|
||||
<template #title v-if="!val.meta.link || (val.meta.link && val.meta.linkType == 1)">
|
||||
<span>{{ val.meta.title }}</span>
|
||||
</template>
|
||||
<template #title v-else>
|
||||
|
||||
@@ -67,17 +67,20 @@
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" v-if="form.type === menuTypeValue">
|
||||
<el-form-item class="w100" prop="code" label="是否iframe">
|
||||
<el-select class="w100" @change="changeIsIframe" v-model="form.meta.isIframe" placeholder="请选择">
|
||||
<el-option v-for="item in trueFalseOption" :key="item.value" :label="item.label"
|
||||
:value="item.value"> </el-option>
|
||||
<el-form-item class="w100" prop="code" label="外链">
|
||||
<el-select class="w100" @change="changeIsIframe" v-model="form.meta.linkType" placeholder="请选择">
|
||||
<!-- <el-option v-for="item in trueFalseOption" :key="item.value" :label="item.label"
|
||||
:value="item.value"> </el-option> -->
|
||||
<el-option :key="0" label="否" :value="0"> </el-option>
|
||||
<el-option :key="1" label="内嵌" :value="1"> </el-option>
|
||||
<el-option :key="2" label="外链" :value="2"> </el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20"
|
||||
v-if="form.type === menuTypeValue && form.meta.isIframe">
|
||||
<el-form-item prop="code" label="iframe地址" class="w100">
|
||||
<el-input v-model.trim="form.meta.link" placeholder="请输入iframe url(http://xxx.com)"></el-input>
|
||||
v-if="form.type === menuTypeValue && form.meta.linkType > 0">
|
||||
<el-form-item prop="code" label="链接地址" class="w100">
|
||||
<el-input v-model.trim="form.meta.link" placeholder="外链/内嵌的链接地址(http://xxx.com)"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
@@ -131,7 +134,7 @@ const defaultMeta = {
|
||||
isKeepAlive: true,
|
||||
isHide: false,
|
||||
isAffix: false,
|
||||
isIframe: false,
|
||||
linkType: 0,
|
||||
link: '',
|
||||
};
|
||||
|
||||
@@ -180,7 +183,7 @@ const state = reactive({
|
||||
isKeepAlive: true,
|
||||
isHide: false,
|
||||
isAffix: false,
|
||||
isIframe: false,
|
||||
linkType: 0,
|
||||
link: '',
|
||||
},
|
||||
},
|
||||
@@ -210,7 +213,7 @@ watch(props, (newValue: any) => {
|
||||
state.form.meta.isKeepAlive = meta.isKeepAlive ? true : false;
|
||||
state.form.meta.isHide = meta.isHide ? true : false;
|
||||
state.form.meta.isAffix = meta.isAffix ? true : false;
|
||||
state.form.meta.isIframe = meta.isIframe ? true : false;
|
||||
state.form.meta.linkType = meta.linkType;
|
||||
});
|
||||
|
||||
// 改变iframe字段,如果为是,则设置默认的组件
|
||||
@@ -263,8 +266,8 @@ const parseMenuMeta = (meta: any) => {
|
||||
if (meta.isAffix) {
|
||||
metaForm.isAffix = true;
|
||||
}
|
||||
if (meta.isIframe) {
|
||||
metaForm.isIframe = true;
|
||||
if (meta.linkType) {
|
||||
metaForm.linkType = meta.linkType;
|
||||
}
|
||||
if (meta.link) {
|
||||
metaForm.link = meta.link;
|
||||
|
||||
@@ -77,11 +77,11 @@
|
||||
<el-descriptions-item v-if="infoDialog.data.type == menuTypeValue" label="tag不可删除">
|
||||
{{ infoDialog.data.meta.isAffix ? '是' : '否' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item v-if="infoDialog.data.type == menuTypeValue" label="是否iframe">
|
||||
{{ infoDialog.data.meta.isIframe ? '是' : '否' }}
|
||||
<el-descriptions-item v-if="infoDialog.data.type == menuTypeValue" label="外链">
|
||||
{{ infoDialog.data.meta.linkType ? '是' : '否' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item v-if="infoDialog.data.type == menuTypeValue && infoDialog.data.meta.isIframe"
|
||||
label="iframe url">
|
||||
<el-descriptions-item v-if="infoDialog.data.type == menuTypeValue && infoDialog.data.meta.linkType > 0"
|
||||
label="外链">
|
||||
{{ infoDialog.data.meta.link }}
|
||||
</el-descriptions-item>
|
||||
|
||||
|
||||
@@ -1850,10 +1850,10 @@ uri-js@^4.2.2:
|
||||
dependencies:
|
||||
punycode "^2.1.0"
|
||||
|
||||
vite@^4.3.8:
|
||||
version "4.3.8"
|
||||
resolved "https://registry.npmmirror.com/vite/-/vite-4.3.8.tgz#70cd6a294ab52d7fb8f37f5bc63d117dd19e9918"
|
||||
integrity sha512-uYB8PwN7hbMrf4j1xzGDk/lqjsZvCDbt/JC5dyfxc19Pg8kRm14LinK/uq+HSLNswZEoKmweGdtpbnxRtrAXiQ==
|
||||
vite@^4.3.9:
|
||||
version "4.3.9"
|
||||
resolved "https://registry.npmmirror.com/vite/-/vite-4.3.9.tgz#db896200c0b1aa13b37cdc35c9e99ee2fdd5f96d"
|
||||
integrity sha512-qsTNZjO9NoJNW7KnOrgYwczm0WctJ8m/yqYAMAK9Lxt4SoySUfS5S8ia9K7JHpa3KEeMfyF8LoJ3c5NeBJy6pg==
|
||||
dependencies:
|
||||
esbuild "^0.17.5"
|
||||
postcss "^8.4.23"
|
||||
@@ -1904,10 +1904,10 @@ vue-eslint-parser@^9.1.1:
|
||||
lodash "^4.17.21"
|
||||
semver "^7.3.6"
|
||||
|
||||
vue-router@^4.2.1:
|
||||
version "4.2.1"
|
||||
resolved "https://registry.npmmirror.com/vue-router/-/vue-router-4.2.1.tgz#f8ab85c89e74682cad71519480fdf2b855e8c9e0"
|
||||
integrity sha512-nW28EeifEp8Abc5AfmAShy5ZKGsGzjcnZ3L1yc2DYUo+MqbBClrRP9yda3dIekM4I50/KnEwo1wkBLf7kHH5Cw==
|
||||
vue-router@^4.2.2:
|
||||
version "4.2.2"
|
||||
resolved "https://registry.npmmirror.com/vue-router/-/vue-router-4.2.2.tgz#b0097b66d89ca81c0986be03da244c7b32a4fd81"
|
||||
integrity sha512-cChBPPmAflgBGmy3tBsjeoe3f3VOSG6naKyY5pjtrqLGbNEXdzCigFUHgBvp9e3ysAtFtEx7OLqcSDh/1Cq2TQ==
|
||||
dependencies:
|
||||
"@vue/devtools-api" "^6.5.0"
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ func (d *Db) ExecSql(rc *req.Ctx) {
|
||||
}
|
||||
}
|
||||
|
||||
colAndRes := make(map[string]interface{})
|
||||
colAndRes := make(map[string]any)
|
||||
colAndRes["colNames"] = execResAll.ColNames
|
||||
colAndRes["res"] = execResAll.Res
|
||||
rc.ResData = colAndRes
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
|
||||
type Db interface {
|
||||
// 分页获取
|
||||
GetPageList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
Count(condition *entity.DbQuery) int64
|
||||
|
||||
@@ -58,7 +58,7 @@ type dbAppImpl struct {
|
||||
}
|
||||
|
||||
// 分页获取数据库信息列表
|
||||
func (d *dbAppImpl) GetPageList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (d *dbAppImpl) GetPageList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return d.dbRepo.GetDbList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
@@ -108,19 +108,19 @@ func (d *dbAppImpl) Save(dbEntity *entity.Db) {
|
||||
dbId := dbEntity.Id
|
||||
old := d.GetById(dbId)
|
||||
|
||||
var oldDbs []interface{}
|
||||
var oldDbs []any
|
||||
for _, v := range strings.Split(old.Database, " ") {
|
||||
// 关闭数据库连接
|
||||
CloseDb(dbEntity.Id, v)
|
||||
oldDbs = append(oldDbs, v)
|
||||
}
|
||||
|
||||
var newDbs []interface{}
|
||||
var newDbs []any
|
||||
for _, v := range strings.Split(dbEntity.Database, " ") {
|
||||
newDbs = append(newDbs, v)
|
||||
}
|
||||
// 比较新旧数据库列表,需要将移除的数据库相关联的信息删除
|
||||
_, delDb, _ := utils.ArrayCompare(newDbs, oldDbs, func(i1, i2 interface{}) bool {
|
||||
_, delDb, _ := utils.ArrayCompare(newDbs, oldDbs, func(i1, i2 any) bool {
|
||||
return i1.(string) == i2.(string)
|
||||
})
|
||||
for _, v := range delDb {
|
||||
@@ -295,7 +295,7 @@ func (d *DbInstance) Close() {
|
||||
// 客户端连接缓存,指定时间内没有访问则会被关闭, key为数据库实例id:数据库
|
||||
var dbCache = cache.NewTimedCache(constant.DbConnExpireTime, 5*time.Second).
|
||||
WithUpdateAccessTime(true).
|
||||
OnEvicted(func(key interface{}, value interface{}) {
|
||||
OnEvicted(func(key any, value any) {
|
||||
global.Log.Info(fmt.Sprintf("删除db连接缓存 id = %s", key))
|
||||
value.(*DbInstance).Close()
|
||||
})
|
||||
@@ -353,7 +353,7 @@ func GetDbConn(d *entity.Db, db string) (*sql.DB, error) {
|
||||
return DB, nil
|
||||
}
|
||||
|
||||
func SelectDataByDb(db *sql.DB, selectSql string) ([]string, []map[string]interface{}, error) {
|
||||
func SelectDataByDb(db *sql.DB, selectSql string) ([]string, []map[string]any, error) {
|
||||
rows, err := db.Query(selectSql)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -367,7 +367,7 @@ func SelectDataByDb(db *sql.DB, selectSql string) ([]string, []map[string]interf
|
||||
}()
|
||||
colTypes, _ := rows.ColumnTypes()
|
||||
// 这里表示一行填充数据
|
||||
scans := make([]interface{}, len(colTypes))
|
||||
scans := make([]any, len(colTypes))
|
||||
// 这里表示一行所有列的值,用[]byte表示
|
||||
vals := make([][]byte, len(colTypes))
|
||||
// 这里scans引用vals,把数据填充到[]byte里
|
||||
@@ -375,7 +375,7 @@ func SelectDataByDb(db *sql.DB, selectSql string) ([]string, []map[string]interf
|
||||
scans[k] = &vals[k]
|
||||
}
|
||||
|
||||
result := make([]map[string]interface{}, 0)
|
||||
result := make([]map[string]any, 0)
|
||||
// 列名用于前端表头名称按照数据库与查询字段顺序显示
|
||||
colNames := make([]string, 0)
|
||||
// 是否第一次遍历,列名数组只需第一次遍历时加入
|
||||
@@ -387,7 +387,7 @@ func SelectDataByDb(db *sql.DB, selectSql string) ([]string, []map[string]interf
|
||||
return nil, nil, err
|
||||
}
|
||||
// 每行数据
|
||||
rowData := make(map[string]interface{})
|
||||
rowData := make(map[string]any)
|
||||
// 把vals中的数据复制到row中
|
||||
for i, v := range vals {
|
||||
colType := colTypes[i]
|
||||
@@ -406,7 +406,7 @@ func SelectDataByDb(db *sql.DB, selectSql string) ([]string, []map[string]interf
|
||||
}
|
||||
|
||||
// 将查询的值转为对应列类型的实际值,不全部转为字符串
|
||||
func valueConvert(data []byte, colType *sql.ColumnType) interface{} {
|
||||
func valueConvert(data []byte, colType *sql.ColumnType) any {
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -455,7 +455,7 @@ func valueConvert(data []byte, colType *sql.ColumnType) interface{} {
|
||||
}
|
||||
|
||||
// 查询数据结果映射至struct。可参考sqlx库
|
||||
func Select2StructByDb(db *sql.DB, selectSql string, dest interface{}) error {
|
||||
func Select2StructByDb(db *sql.DB, selectSql string, dest any) error {
|
||||
rows, err := db.Query(selectSql)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -26,7 +26,7 @@ type DbSqlExecReq struct {
|
||||
|
||||
type DbSqlExecRes struct {
|
||||
ColNames []string
|
||||
Res []map[string]interface{}
|
||||
Res []map[string]any
|
||||
}
|
||||
|
||||
// 合并执行结果,主要用于执行多条sql使用
|
||||
@@ -52,7 +52,7 @@ type DbSqlExec interface {
|
||||
DeleteBy(condition *entity.DbSqlExec)
|
||||
|
||||
// 分页获取
|
||||
GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
}
|
||||
|
||||
func newDbSqlExecApp(dbExecSqlRepo repository.DbSqlExec) DbSqlExec {
|
||||
@@ -151,7 +151,7 @@ func (d *dbSqlExecAppImpl) DeleteBy(condition *entity.DbSqlExec) {
|
||||
d.dbSqlExecRepo.DeleteBy(condition)
|
||||
}
|
||||
|
||||
func (d *dbSqlExecAppImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (d *dbSqlExecAppImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return d.dbSqlExecRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
@@ -256,8 +256,8 @@ func doExec(sql string, dbInstance *DbInstance) (*DbSqlExecRes, error) {
|
||||
if err != nil {
|
||||
execRes = err.Error()
|
||||
}
|
||||
res := make([]map[string]interface{}, 0)
|
||||
resData := make(map[string]interface{})
|
||||
res := make([]map[string]any, 0)
|
||||
resData := make(map[string]any)
|
||||
resData["rowsAffected"] = rowsAffected
|
||||
resData["sql"] = sql
|
||||
resData["result"] = execRes
|
||||
|
||||
@@ -62,7 +62,7 @@ type DbMetadata interface {
|
||||
|
||||
// 获取指定表的数据-分页查询
|
||||
// @return columns: 列字段名;result: 结果集;error: 错误
|
||||
GetTableRecord(tableName string, pageNum, pageSize int) ([]string, []map[string]interface{}, error)
|
||||
GetTableRecord(tableName string, pageNum, pageSize int) ([]string, []map[string]any, error)
|
||||
}
|
||||
|
||||
// ------------------------- 元数据sql操作 -------------------------
|
||||
|
||||
@@ -156,6 +156,6 @@ func (mm *MysqlMetadata) GetCreateTableDdl(tableName string) string {
|
||||
return res[0]["Create Table"].(string)
|
||||
}
|
||||
|
||||
func (mm *MysqlMetadata) GetTableRecord(tableName string, pageNum, pageSize int) ([]string, []map[string]interface{}, error) {
|
||||
func (mm *MysqlMetadata) GetTableRecord(tableName string, pageNum, pageSize int) ([]string, []map[string]any, error) {
|
||||
return mm.di.SelectData(fmt.Sprintf("SELECT * FROM %s LIMIT %d, %d", tableName, (pageNum-1)*pageSize, pageSize))
|
||||
}
|
||||
|
||||
@@ -175,6 +175,6 @@ func (pm *PgsqlMetadata) GetCreateTableDdl(tableName string) string {
|
||||
return res[0]["sql"].(string)
|
||||
}
|
||||
|
||||
func (pm *PgsqlMetadata) GetTableRecord(tableName string, pageNum, pageSize int) ([]string, []map[string]interface{}, error) {
|
||||
func (pm *PgsqlMetadata) GetTableRecord(tableName string, pageNum, pageSize int) ([]string, []map[string]any, error) {
|
||||
return pm.di.SelectData(fmt.Sprintf("SELECT * FROM %s OFFSET %d LIMIT %d", tableName, (pageNum-1)*pageSize, pageSize))
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
// 将结果scan至结构体,copy至 sqlx库: https://github.com/jmoiron/sqlx
|
||||
func scanAll(rows *sql.Rows, dest interface{}, structOnly bool) error {
|
||||
func scanAll(rows *sql.Rows, dest any, structOnly bool) error {
|
||||
var v, vp reflect.Value
|
||||
|
||||
value := reflect.ValueOf(dest)
|
||||
@@ -50,7 +50,7 @@ func scanAll(rows *sql.Rows, dest interface{}, structOnly bool) error {
|
||||
}
|
||||
|
||||
if !scannable {
|
||||
var values []interface{}
|
||||
var values []any
|
||||
var m *Mapper = mapper()
|
||||
|
||||
fields := m.TraversalsByName(base, columns)
|
||||
@@ -58,7 +58,7 @@ func scanAll(rows *sql.Rows, dest interface{}, structOnly bool) error {
|
||||
if f, err := missingFields(fields); err != nil {
|
||||
return fmt.Errorf("missing destination name %s in %T", columns[f], dest)
|
||||
}
|
||||
values = make([]interface{}, len(columns))
|
||||
values = make([]any, len(columns))
|
||||
|
||||
for rows.Next() {
|
||||
// create a new struct type (which returns PtrTo) and indirect it
|
||||
@@ -178,7 +178,7 @@ func missingFields(transversals [][]int) (field int, err error) {
|
||||
// when iterating over many rows. Empty traversals will get an interface pointer.
|
||||
// Because of the necessity of requesting ptrs or values, it's considered a bit too
|
||||
// specialized for inclusion in reflectx itself.
|
||||
func fieldsByTraversal(v reflect.Value, traversals [][]int, values []interface{}, ptrs bool) error {
|
||||
func fieldsByTraversal(v reflect.Value, traversals [][]int, values []any, ptrs bool) error {
|
||||
v = reflect.Indirect(v)
|
||||
if v.Kind() != reflect.Struct {
|
||||
return errors.New("argument not a struct")
|
||||
@@ -186,7 +186,7 @@ func fieldsByTraversal(v reflect.Value, traversals [][]int, values []interface{}
|
||||
|
||||
for i, traversal := range traversals {
|
||||
if len(traversal) == 0 {
|
||||
values[i] = new(interface{})
|
||||
values[i] = new(any)
|
||||
continue
|
||||
}
|
||||
f := FieldByIndexes(v, traversal)
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
type Db interface {
|
||||
// 分页获取机器信息列表
|
||||
GetDbList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetDbList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
Count(condition *entity.DbQuery) int64
|
||||
|
||||
|
||||
@@ -11,5 +11,5 @@ type DbSqlExec interface {
|
||||
DeleteBy(condition *entity.DbSqlExec)
|
||||
|
||||
// 分页获取
|
||||
GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
}
|
||||
|
||||
@@ -17,10 +17,10 @@ func newDbRepo() repository.Db {
|
||||
}
|
||||
|
||||
// 分页获取数据库信息列表
|
||||
func (d *dbRepoImpl) GetDbList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (d *dbRepoImpl) GetDbList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
sql := "SELECT d.* FROM t_db d WHERE 1 = 1 "
|
||||
|
||||
values := make([]interface{}, 0)
|
||||
values := make([]any, 0)
|
||||
if condition.Host != "" {
|
||||
sql = sql + " AND d.host LIKE ?"
|
||||
values = append(values, "%"+condition.Host+"%")
|
||||
@@ -41,7 +41,7 @@ func (d *dbRepoImpl) GetDbList(condition *entity.DbQuery, pageParam *model.PageP
|
||||
}
|
||||
|
||||
func (d *dbRepoImpl) Count(condition *entity.DbQuery) int64 {
|
||||
where := make(map[string]interface{})
|
||||
where := make(map[string]any)
|
||||
if len(condition.TagIds) > 0 {
|
||||
where["tag_id"] = condition.TagIds
|
||||
}
|
||||
|
||||
@@ -22,6 +22,6 @@ func (d *dbSqlExecRepoImpl) DeleteBy(condition *entity.DbSqlExec) {
|
||||
}
|
||||
|
||||
// 分页获取
|
||||
func (d *dbSqlExecRepoImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (d *dbSqlExecRepoImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type AuthCert interface {
|
||||
GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
Save(ac *entity.AuthCert)
|
||||
|
||||
@@ -29,7 +29,7 @@ type authCertAppImpl struct {
|
||||
authCertRepo repository.AuthCert
|
||||
}
|
||||
|
||||
func (a *authCertAppImpl) GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (a *authCertAppImpl) GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return a.authCertRepo.GetPageList(condition, pageParam, toEntity)
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ type Machine interface {
|
||||
GetById(id uint64, cols ...string) *entity.Machine
|
||||
|
||||
// 分页获取机器信息列表
|
||||
GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
// 获取机器连接
|
||||
GetCli(id uint64) *machine.Cli
|
||||
@@ -52,7 +52,7 @@ type machineAppImpl struct {
|
||||
}
|
||||
|
||||
// 分页获取机器信息列表
|
||||
func (m *machineAppImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (m *machineAppImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return m.machineRepo.GetMachineList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
|
||||
type MachineFile interface {
|
||||
// 分页获取机器文件信息列表
|
||||
GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
// 根据条件获取
|
||||
GetMachineFile(condition *entity.MachineFile, cols ...string) error
|
||||
@@ -67,7 +67,7 @@ type machineFileAppImpl struct {
|
||||
}
|
||||
|
||||
// 分页获取机器脚本信息列表
|
||||
func (m *machineFileAppImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (m *machineFileAppImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return m.machineFileRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
type MachineScript interface {
|
||||
// 分页获取机器脚本信息列表
|
||||
GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
// 根据条件获取
|
||||
GetMachineScript(condition *entity.MachineScript, cols ...string) error
|
||||
@@ -40,7 +40,7 @@ const Common_Script_Machine_Id = 9999999
|
||||
// machineScriptRepo: persistence.MachineScriptDao}
|
||||
|
||||
// 分页获取机器脚本信息列表
|
||||
func (m *machineScriptAppImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (m *machineScriptAppImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return m.machineScriptRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type AuthCert interface {
|
||||
GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
Insert(ac *entity.AuthCert)
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
type Machine interface {
|
||||
// 分页获取机器信息列表
|
||||
GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
Count(condition *entity.MachineQuery) int64
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
type MachineFile interface {
|
||||
// 分页获取机器脚本信息列表
|
||||
GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
// 根据条件获取
|
||||
GetMachineFile(condition *entity.MachineFile, cols ...string) error
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
type MachineScript interface {
|
||||
// 分页获取机器脚本信息列表
|
||||
GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
// 根据条件获取
|
||||
GetMachineScript(condition *entity.MachineScript, cols ...string) error
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type MachineTaskConfig interface {
|
||||
GetPageList(condition *entity.MachineTaskConfig, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.MachineTaskConfig, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
// 根据条件获取
|
||||
GetBy(condition *entity.MachineTaskConfig, cols ...string) error
|
||||
|
||||
@@ -140,7 +140,7 @@ func (c *Cli) GetMachine() *Info {
|
||||
// 机器客户端连接缓存,指定时间内没有访问则会被关闭
|
||||
var cliCache = cache.NewTimedCache(constant.MachineConnExpireTime, 5*time.Second).
|
||||
WithUpdateAccessTime(true).
|
||||
OnEvicted(func(_, value interface{}) {
|
||||
OnEvicted(func(_, value any) {
|
||||
value.(*Cli).Close()
|
||||
})
|
||||
|
||||
@@ -172,7 +172,7 @@ func DeleteCli(id uint64) {
|
||||
|
||||
// 从缓存中获取客户端信息,不存在则回调获取机器信息函数,并新建
|
||||
func GetCli(machineId uint64, getMachine func(uint64) *Info) (*Cli, error) {
|
||||
cli, err := cliCache.ComputeIfAbsent(machineId, func(_ interface{}) (interface{}, error) {
|
||||
cli, err := cliCache.ComputeIfAbsent(machineId, func(_ any) (any, error) {
|
||||
me := getMachine(machineId)
|
||||
err := IfUseSshTunnelChangeIpPort(me, getMachine)
|
||||
if err != nil {
|
||||
|
||||
@@ -68,7 +68,7 @@ func TestTemplateRev(t *testing.T) {
|
||||
//next := temp[ei:]
|
||||
//key := temp[index+1 : ei-1]
|
||||
//value := SubString(str, index, UnicodeIndex(str, next))
|
||||
res := make(map[string]interface{})
|
||||
res := make(map[string]any)
|
||||
utils.ReverStrTemplate(temp, str, res)
|
||||
fmt.Println(res)
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func (rec *Recorder) WriteHeader(height, width int) {
|
||||
}
|
||||
|
||||
func (rec *Recorder) WriteData(rectype RecType, data string) {
|
||||
recData := make([]interface{}, 3)
|
||||
recData := make([]any, 3)
|
||||
recData[0] = float64(time.Since(rec.StartTime).Microseconds()) / float64(1000000)
|
||||
recData[1] = rectype
|
||||
recData[2] = data
|
||||
|
||||
@@ -13,7 +13,7 @@ func newAuthCertRepo() repository.AuthCert {
|
||||
return new(authCertRepoImpl)
|
||||
}
|
||||
|
||||
func (m *authCertRepoImpl) GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (m *authCertRepoImpl) GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, condition, toEntity)
|
||||
}
|
||||
|
||||
|
||||
@@ -15,10 +15,10 @@ func newMachineRepo() repository.Machine {
|
||||
}
|
||||
|
||||
// 分页获取机器信息列表
|
||||
func (m *machineRepoImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (m *machineRepoImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
sql := "SELECT m.* FROM t_machine m WHERE 1 = 1 "
|
||||
|
||||
values := make([]interface{}, 0)
|
||||
values := make([]any, 0)
|
||||
if condition.Ip != "" {
|
||||
sql = sql + " AND m.ip LIKE ?"
|
||||
values = append(values, "%"+condition.Ip+"%")
|
||||
@@ -40,7 +40,7 @@ func (m *machineRepoImpl) GetMachineList(condition *entity.MachineQuery, pagePar
|
||||
}
|
||||
|
||||
func (m *machineRepoImpl) Count(condition *entity.MachineQuery) int64 {
|
||||
where := make(map[string]interface{})
|
||||
where := make(map[string]any)
|
||||
if len(condition.TagIds) > 0 {
|
||||
where["tag_id"] = condition.TagIds
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ func newMachineFileRepo() repository.MachineFile {
|
||||
}
|
||||
|
||||
// 分页获取机器文件信息列表
|
||||
func (m *machineFileRepoImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (m *machineFileRepoImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ func newMachineScriptRepo() repository.MachineScript {
|
||||
}
|
||||
|
||||
// 分页获取机器信息列表
|
||||
func (m *machineScriptRepoImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (m *machineScriptRepoImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
|
||||
@@ -10,30 +10,30 @@ type Mongo struct {
|
||||
}
|
||||
|
||||
type MongoCommand struct {
|
||||
Database string `binding:"required" json:"database"`
|
||||
Collection string `binding:"required" json:"collection"`
|
||||
Filter map[string]interface{} `json:"filter"`
|
||||
Database string `binding:"required" json:"database"`
|
||||
Collection string `binding:"required" json:"collection"`
|
||||
Filter map[string]any `json:"filter"`
|
||||
}
|
||||
|
||||
type MongoRunCommand struct {
|
||||
Database string `binding:"required" json:"database"`
|
||||
Command map[string]interface{} `json:"command"`
|
||||
Database string `binding:"required" json:"database"`
|
||||
Command map[string]any `json:"command"`
|
||||
}
|
||||
|
||||
type MongoFindCommand struct {
|
||||
MongoCommand
|
||||
Sort map[string]interface{} `json:"sort"`
|
||||
Sort map[string]any `json:"sort"`
|
||||
Skip int64
|
||||
Limit int64
|
||||
}
|
||||
|
||||
type MongoUpdateByIdCommand struct {
|
||||
MongoCommand
|
||||
DocId interface{} `binding:"required" json:"docId"`
|
||||
Update map[string]interface{} `json:"update"`
|
||||
DocId any `binding:"required" json:"docId"`
|
||||
Update map[string]any `json:"update"`
|
||||
}
|
||||
|
||||
type MongoInsertCommand struct {
|
||||
MongoCommand
|
||||
Doc map[string]interface{} `json:"doc"`
|
||||
Doc map[string]any `json:"doc"`
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
|
||||
type Mongo interface {
|
||||
// 分页获取机器脚本信息列表
|
||||
GetPageList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
Count(condition *entity.MongoQuery) int64
|
||||
|
||||
@@ -54,7 +54,7 @@ type mongoAppImpl struct {
|
||||
}
|
||||
|
||||
// 分页获取数据库信息列表
|
||||
func (d *mongoAppImpl) GetPageList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (d *mongoAppImpl) GetPageList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return d.mongoRepo.GetList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ func (d *mongoAppImpl) GetMongoCli(id uint64) *mongo.Client {
|
||||
// mongo客户端连接缓存,指定时间内没有访问则会被关闭
|
||||
var mongoCliCache = cache.NewTimedCache(constant.MongoConnExpireTime, 5*time.Second).
|
||||
WithUpdateAccessTime(true).
|
||||
OnEvicted(func(key interface{}, value interface{}) {
|
||||
OnEvicted(func(key any, value any) {
|
||||
global.Log.Info("删除mongo连接缓存: id = ", key)
|
||||
value.(*MongoInstance).Close()
|
||||
})
|
||||
@@ -122,7 +122,7 @@ func init() {
|
||||
|
||||
// 获取mongo的连接实例
|
||||
func GetMongoInstance(mongoId uint64, getMongoEntity func(uint64) *entity.Mongo) (*MongoInstance, error) {
|
||||
mi, err := mongoCliCache.ComputeIfAbsent(mongoId, func(_ interface{}) (interface{}, error) {
|
||||
mi, err := mongoCliCache.ComputeIfAbsent(mongoId, func(_ any) (any, error) {
|
||||
c, err := connect(getMongoEntity(mongoId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
type Mongo interface {
|
||||
// 分页获取列表
|
||||
GetList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
Count(condition *entity.MongoQuery) int64
|
||||
|
||||
|
||||
@@ -17,14 +17,14 @@ func newMongoRepo() repository.Mongo {
|
||||
}
|
||||
|
||||
// 分页获取数据库信息列表
|
||||
func (d *mongoRepoImpl) GetList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (d *mongoRepoImpl) GetList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
sql := "SELECT d.* FROM t_mongo d WHERE 1=1 "
|
||||
|
||||
if len(condition.TagIds) > 0 {
|
||||
sql = sql + " AND d.tag_id IN " + fmt.Sprintf("(%s)", strings.Join(utils.NumberArr2StrArr(condition.TagIds), ","))
|
||||
}
|
||||
|
||||
values := make([]interface{}, 0)
|
||||
values := make([]any, 0)
|
||||
if condition.TagPathLike != "" {
|
||||
values = append(values, condition.TagPathLike+"%")
|
||||
sql = sql + " AND d.tag_path LIKE ?"
|
||||
@@ -34,7 +34,7 @@ func (d *mongoRepoImpl) GetList(condition *entity.MongoQuery, pageParam *model.P
|
||||
}
|
||||
|
||||
func (d *mongoRepoImpl) Count(condition *entity.MongoQuery) int64 {
|
||||
where := make(map[string]interface{})
|
||||
where := make(map[string]any)
|
||||
if len(condition.TagIds) > 0 {
|
||||
where["tag_id"] = condition.TagIds
|
||||
}
|
||||
|
||||
@@ -30,29 +30,29 @@ type KeyInfo struct {
|
||||
|
||||
type StringValue struct {
|
||||
KeyInfo
|
||||
Value interface{} `binding:"required" json:"value"`
|
||||
Value any `binding:"required" json:"value"`
|
||||
}
|
||||
|
||||
type HashValue struct {
|
||||
KeyInfo
|
||||
Value []map[string]interface{} `binding:"required" json:"value"`
|
||||
Value []map[string]any `binding:"required" json:"value"`
|
||||
}
|
||||
|
||||
type SetValue struct {
|
||||
KeyInfo
|
||||
Value []interface{} `binding:"required" json:"value"`
|
||||
Value []any `binding:"required" json:"value"`
|
||||
}
|
||||
|
||||
type ListValue struct {
|
||||
KeyInfo
|
||||
Value []interface{} `binding:"required" json:"value"`
|
||||
Value []any `binding:"required" json:"value"`
|
||||
}
|
||||
|
||||
// list lset命令参数入参
|
||||
type ListSetValue struct {
|
||||
Key string `binding:"required" json:"key"`
|
||||
Index int64
|
||||
Value interface{} `binding:"required" json:"value"`
|
||||
Value any `binding:"required" json:"value"`
|
||||
}
|
||||
|
||||
type RedisScanForm struct {
|
||||
|
||||
@@ -23,7 +23,7 @@ func (r *Redis) Hscan(rc *req.Ctx) {
|
||||
keySize, err := cmdable.HLen(contextTodo, key).Result()
|
||||
biz.ErrIsNilAppendErr(err, "hlen err: %s")
|
||||
|
||||
rc.ResData = map[string]interface{}{
|
||||
rc.ResData = map[string]any{
|
||||
"keys": keys,
|
||||
"cursor": nextCursor,
|
||||
"keySize": keySize,
|
||||
|
||||
@@ -22,7 +22,7 @@ func (r *Redis) GetListValue(rc *req.Ctx) {
|
||||
res, err := cmdable.LRange(ctx, key, int64(start), int64(stop)).Result()
|
||||
biz.ErrIsNilAppendErr(err, "获取list值失败: %s")
|
||||
|
||||
rc.ResData = map[string]interface{}{
|
||||
rc.ResData = map[string]any{
|
||||
"len": len,
|
||||
"list": res,
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ func (r *Redis) ClusterInfo(rc *req.Ctx) {
|
||||
}
|
||||
nodesRes = append(nodesRes, node)
|
||||
}
|
||||
rc.ResData = map[string]interface{}{
|
||||
rc.ResData = map[string]any{
|
||||
"clusterInfo": info,
|
||||
"clusterNodes": nodesRes,
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ func (r *Redis) Sscan(rc *req.Ctx) {
|
||||
cmd := r.getRedisIns(rc).GetCmdable()
|
||||
keys, cursor, err := cmd.SScan(context.TODO(), scan.Key, scan.Cursor, scan.Match, scan.Count).Result()
|
||||
biz.ErrIsNilAppendErr(err, "sscan失败: %s")
|
||||
rc.ResData = map[string]interface{}{
|
||||
rc.ResData = map[string]any{
|
||||
"keys": keys,
|
||||
"cursor": cursor,
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func (r *Redis) ZScan(rc *req.Ctx) {
|
||||
|
||||
keys, cursor, err := ri.GetCmdable().ZScan(context.TODO(), key, cursor, match, int64(count)).Result()
|
||||
biz.ErrIsNilAppendErr(err, "sscan失败: %s")
|
||||
rc.ResData = map[string]interface{}{
|
||||
rc.ResData = map[string]any{
|
||||
"keys": keys,
|
||||
"cursor": cursor,
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
|
||||
type Redis interface {
|
||||
// 分页获取机器脚本信息列表
|
||||
GetPageList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
Count(condition *entity.RedisQuery) int64
|
||||
|
||||
@@ -55,7 +55,7 @@ type redisAppImpl struct {
|
||||
}
|
||||
|
||||
// 分页获取机器脚本信息列表
|
||||
func (r *redisAppImpl) GetPageList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (r *redisAppImpl) GetPageList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return r.redisRepo.GetRedisList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ func getRedisDialer(machineId int) func(ctx context.Context, network, addr strin
|
||||
// redis客户端连接缓存,指定时间内没有访问则会被关闭
|
||||
var redisCache = cache.NewTimedCache(constant.RedisConnExpireTime, 5*time.Second).
|
||||
WithUpdateAccessTime(true).
|
||||
OnEvicted(func(key interface{}, value interface{}) {
|
||||
OnEvicted(func(key any, value any) {
|
||||
global.Log.Info(fmt.Sprintf("删除redis连接缓存 id = %s", key))
|
||||
value.(*RedisInstance).Close()
|
||||
})
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
type Redis interface {
|
||||
// 分页获取机器信息列表
|
||||
GetRedisList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetRedisList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
Count(condition *entity.RedisQuery) int64
|
||||
|
||||
|
||||
@@ -17,9 +17,9 @@ func newRedisRepo() repository.Redis {
|
||||
}
|
||||
|
||||
// 分页获取机器信息列表
|
||||
func (r *redisRepoImpl) GetRedisList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (r *redisRepoImpl) GetRedisList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
sql := "SELECT d.* FROM t_redis d WHERE 1=1 "
|
||||
values := make([]interface{}, 0)
|
||||
values := make([]any, 0)
|
||||
if condition.Host != "" {
|
||||
sql = sql + " AND d.host LIKE ?"
|
||||
values = append(values, "%"+condition.Host+"%")
|
||||
@@ -36,7 +36,7 @@ func (r *redisRepoImpl) GetRedisList(condition *entity.RedisQuery, pageParam *mo
|
||||
}
|
||||
|
||||
func (r *redisRepoImpl) Count(condition *entity.RedisQuery) int64 {
|
||||
where := make(map[string]interface{})
|
||||
where := make(map[string]any)
|
||||
if len(condition.TagIds) > 0 {
|
||||
where["tag_id"] = condition.TagIds
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func (a *Account) Login(rc *req.Ctx) {
|
||||
// 保存登录消息
|
||||
go a.saveLogin(account, clientIp)
|
||||
|
||||
rc.ResData = map[string]interface{}{
|
||||
rc.ResData = map[string]any{
|
||||
"token": req.CreateToken(account.Id, account.Username),
|
||||
"name": account.Name,
|
||||
"username": account.Username,
|
||||
@@ -84,7 +84,7 @@ func (a *Account) GetPermissions(rc *req.Ctx) {
|
||||
}
|
||||
// 保存该账号的权限codes
|
||||
req.SavePermissionCodes(account.Id, permissions)
|
||||
rc.ResData = map[string]interface{}{
|
||||
rc.ResData = map[string]any{
|
||||
"menus": menus.ToTrees(0),
|
||||
"permissions": permissions,
|
||||
}
|
||||
@@ -268,20 +268,20 @@ func (a *Account) SaveRoles(rc *req.Ctx) {
|
||||
|
||||
// 将,拼接的字符串进行切割
|
||||
idsStr := strings.Split(form.RoleIds, ",")
|
||||
var newIds []interface{}
|
||||
var newIds []any
|
||||
for _, v := range idsStr {
|
||||
id, _ := strconv.Atoi(v)
|
||||
newIds = append(newIds, uint64(id))
|
||||
}
|
||||
|
||||
// 将[]uint64转为[]interface{}
|
||||
// 将[]uint64转为[]any
|
||||
oIds := a.RoleApp.GetAccountRoleIds(uint64(form.Id))
|
||||
var oldIds []interface{}
|
||||
var oldIds []any
|
||||
for _, v := range oIds {
|
||||
oldIds = append(oldIds, v)
|
||||
}
|
||||
|
||||
addIds, delIds, _ := utils.ArrayCompare(newIds, oldIds, func(i1, i2 interface{}) bool {
|
||||
addIds, delIds, _ := utils.ArrayCompare(newIds, oldIds, func(i1, i2 any) bool {
|
||||
return i1.(uint64) == i2.(uint64)
|
||||
})
|
||||
|
||||
|
||||
@@ -7,5 +7,5 @@ import (
|
||||
|
||||
func GenerateCaptcha(rc *req.Ctx) {
|
||||
id, image := captcha.Generate()
|
||||
rc.ResData = map[string]interface{}{"base64Captcha": image, "cid": id}
|
||||
rc.ResData = map[string]any{"base64Captcha": image, "cid": id}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ type ResourceForm struct {
|
||||
Name string `binding:"required"`
|
||||
Type int `binding:"required,oneof=1 2"`
|
||||
Weight int
|
||||
Meta map[string]interface{}
|
||||
Meta map[string]any
|
||||
}
|
||||
|
||||
type MenuResourceMeta struct {
|
||||
|
||||
@@ -69,20 +69,20 @@ func (r *Role) SaveResource(rc *req.Ctx) {
|
||||
|
||||
// 将,拼接的字符串进行切割
|
||||
idsStr := strings.Split(form.ResourceIds, ",")
|
||||
var newIds []interface{}
|
||||
var newIds []any
|
||||
for _, v := range idsStr {
|
||||
id, _ := strconv.Atoi(v)
|
||||
newIds = append(newIds, uint64(id))
|
||||
}
|
||||
|
||||
// 将[]uint64转为[]interface{}
|
||||
// 将[]uint64转为[]any
|
||||
oIds := r.RoleApp.GetRoleResourceIds(uint64(form.Id))
|
||||
var oldIds []interface{}
|
||||
var oldIds []any
|
||||
for _, v := range oIds {
|
||||
oldIds = append(oldIds, v)
|
||||
}
|
||||
|
||||
addIds, delIds, _ := utils.ArrayCompare(newIds, oldIds, func(i1, i2 interface{}) bool {
|
||||
addIds, delIds, _ := utils.ArrayCompare(newIds, oldIds, func(i1, i2 any) bool {
|
||||
return i1.(uint64) == i2.(uint64)
|
||||
})
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
type Account interface {
|
||||
GetAccount(condition *entity.Account, cols ...string) error
|
||||
|
||||
GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
Create(account *entity.Account)
|
||||
|
||||
@@ -37,7 +37,7 @@ func (a *accountAppImpl) GetAccount(condition *entity.Account, cols ...string) e
|
||||
return a.accountRepo.GetAccount(condition, cols...)
|
||||
}
|
||||
|
||||
func (a *accountAppImpl) GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (a *accountAppImpl) GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return a.accountRepo.GetPageList(condition, pageParam, toEntity)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
const SysConfigKeyPrefix = "sys:config:"
|
||||
|
||||
type Config interface {
|
||||
GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
Save(config *entity.Config)
|
||||
|
||||
@@ -31,7 +31,7 @@ type configAppImpl struct {
|
||||
configRepo repository.Config
|
||||
}
|
||||
|
||||
func (a *configAppImpl) GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (a *configAppImpl) GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return a.configRepo.GetPageList(condition, pageParam, toEntity)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
type Msg interface {
|
||||
GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
Create(msg *entity.Msg)
|
||||
|
||||
@@ -27,7 +27,7 @@ type msgAppImpl struct {
|
||||
msgRepo repository.Msg
|
||||
}
|
||||
|
||||
func (a *msgAppImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (a *msgAppImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return a.msgRepo.GetPageList(condition, pageParam, toEntity)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,17 +9,17 @@ import (
|
||||
)
|
||||
|
||||
type Resource interface {
|
||||
GetResourceList(condition *entity.Resource, toEntity interface{}, orderBy ...string)
|
||||
GetResourceList(condition *entity.Resource, toEntity any, orderBy ...string)
|
||||
|
||||
GetById(id uint64, cols ...string) *entity.Resource
|
||||
|
||||
GetByIdIn(ids []uint64, toEntity interface{}, cols ...string)
|
||||
GetByIdIn(ids []uint64, toEntity any, cols ...string)
|
||||
|
||||
Save(entity *entity.Resource)
|
||||
|
||||
Delete(id uint64)
|
||||
|
||||
GetAccountResources(accountId uint64, toEntity interface{})
|
||||
GetAccountResources(accountId uint64, toEntity any)
|
||||
}
|
||||
|
||||
func newResourceApp(resourceRepo repository.Resource) Resource {
|
||||
@@ -32,7 +32,7 @@ type resourceAppImpl struct {
|
||||
resourceRepo repository.Resource
|
||||
}
|
||||
|
||||
func (r *resourceAppImpl) GetResourceList(condition *entity.Resource, toEntity interface{}, orderBy ...string) {
|
||||
func (r *resourceAppImpl) GetResourceList(condition *entity.Resource, toEntity any, orderBy ...string) {
|
||||
r.resourceRepo.GetResourceList(condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func (r *resourceAppImpl) GetById(id uint64, cols ...string) *entity.Resource {
|
||||
return r.resourceRepo.GetById(id, cols...)
|
||||
}
|
||||
|
||||
func (r *resourceAppImpl) GetByIdIn(ids []uint64, toEntity interface{}, orderBy ...string) {
|
||||
func (r *resourceAppImpl) GetByIdIn(ids []uint64, toEntity any, orderBy ...string) {
|
||||
r.resourceRepo.GetByIdIn(ids, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ func (r *resourceAppImpl) Delete(id uint64) {
|
||||
model.DeleteByCondition(&entity.RoleResource{ResourceId: id})
|
||||
}
|
||||
|
||||
func (r *resourceAppImpl) GetAccountResources(accountId uint64, toEntity interface{}) {
|
||||
func (r *resourceAppImpl) GetAccountResources(accountId uint64, toEntity any) {
|
||||
r.resourceRepo.GetAccountResources(accountId, toEntity)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type Role interface {
|
||||
GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
SaveRole(role *entity.Role)
|
||||
|
||||
@@ -16,7 +16,7 @@ type Role interface {
|
||||
|
||||
GetRoleResourceIds(roleId uint64) []uint64
|
||||
|
||||
GetRoleResources(roleId uint64, toEntity interface{})
|
||||
GetRoleResources(roleId uint64, toEntity any)
|
||||
|
||||
// 保存角色资源关联记录
|
||||
SaveRoleResource(rr *entity.RoleResource)
|
||||
@@ -32,7 +32,7 @@ type Role interface {
|
||||
|
||||
DeleteAccountRole(accountId, roleId uint64)
|
||||
|
||||
GetAccountRoles(accountId uint64, toEntity interface{})
|
||||
GetAccountRoles(accountId uint64, toEntity any)
|
||||
}
|
||||
|
||||
func newRoleApp(roleRepo repository.Role) Role {
|
||||
@@ -45,7 +45,7 @@ type roleAppImpl struct {
|
||||
roleRepo repository.Role
|
||||
}
|
||||
|
||||
func (m *roleAppImpl) GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (m *roleAppImpl) GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return m.roleRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ func (m *roleAppImpl) GetRoleResourceIds(roleId uint64) []uint64 {
|
||||
return m.roleRepo.GetRoleResourceIds(roleId)
|
||||
}
|
||||
|
||||
func (m *roleAppImpl) GetRoleResources(roleId uint64, toEntity interface{}) {
|
||||
func (m *roleAppImpl) GetRoleResources(roleId uint64, toEntity any) {
|
||||
m.roleRepo.GetRoleResources(roleId, toEntity)
|
||||
}
|
||||
|
||||
@@ -95,6 +95,6 @@ func (m *roleAppImpl) DeleteAccountRole(accountId, roleId uint64) {
|
||||
m.roleRepo.DeleteAccountRole(accountId, roleId)
|
||||
}
|
||||
|
||||
func (m *roleAppImpl) GetAccountRoles(accountId uint64, toEntity interface{}) {
|
||||
func (m *roleAppImpl) GetAccountRoles(accountId uint64, toEntity any) {
|
||||
m.roleRepo.GetAccountRoles(accountId, toEntity)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
type Syslog interface {
|
||||
GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
// 从请求上下文的参数保存系统日志
|
||||
SaveFromReq(req *req.Ctx)
|
||||
@@ -29,7 +29,7 @@ type syslogAppImpl struct {
|
||||
syslogRepo repository.Syslog
|
||||
}
|
||||
|
||||
func (m *syslogAppImpl) GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (m *syslogAppImpl) GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return m.syslogRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ type Account interface {
|
||||
// 根据条件获取账号信息
|
||||
GetAccount(condition *entity.Account, cols ...string) error
|
||||
|
||||
GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
Insert(account *entity.Account)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type Config interface {
|
||||
GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
Insert(config *entity.Config)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type Msg interface {
|
||||
GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
Insert(msg *entity.Msg)
|
||||
}
|
||||
|
||||
@@ -6,16 +6,16 @@ import (
|
||||
|
||||
type Resource interface {
|
||||
// 获取资源列表
|
||||
GetResourceList(condition *entity.Resource, toEntity interface{}, orderBy ...string)
|
||||
GetResourceList(condition *entity.Resource, toEntity any, orderBy ...string)
|
||||
|
||||
GetById(id uint64, cols ...string) *entity.Resource
|
||||
|
||||
GetByIdIn(ids []uint64, toEntity interface{}, orderBy ...string)
|
||||
GetByIdIn(ids []uint64, toEntity any, orderBy ...string)
|
||||
|
||||
Delete(id uint64)
|
||||
|
||||
GetByCondition(condition *entity.Resource, cols ...string) error
|
||||
|
||||
// 获取账号资源列表
|
||||
GetAccountResources(accountId uint64, toEntity interface{})
|
||||
GetAccountResources(accountId uint64, toEntity any)
|
||||
}
|
||||
|
||||
@@ -6,14 +6,14 @@ import (
|
||||
)
|
||||
|
||||
type Role interface {
|
||||
GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
Delete(id uint64)
|
||||
|
||||
// 获取角色拥有的资源id数组,从role_resource表获取
|
||||
GetRoleResourceIds(roleId uint64) []uint64
|
||||
|
||||
GetRoleResources(roleId uint64, toEntity interface{})
|
||||
GetRoleResources(roleId uint64, toEntity any)
|
||||
|
||||
SaveRoleResource(rr *entity.RoleResource)
|
||||
|
||||
@@ -27,5 +27,5 @@ type Role interface {
|
||||
DeleteAccountRole(accountId, roleId uint64)
|
||||
|
||||
// 获取账号角色信息列表
|
||||
GetAccountRoles(accountId uint64, toEntity interface{})
|
||||
GetAccountRoles(accountId uint64, toEntity any)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type Syslog interface {
|
||||
GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
Insert(log *entity.Syslog)
|
||||
}
|
||||
|
||||
@@ -17,10 +17,10 @@ func (a *accountRepoImpl) GetAccount(condition *entity.Account, cols ...string)
|
||||
return model.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
func (m *accountRepoImpl) GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (m *accountRepoImpl) GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
sql := "SELECT * FROM t_sys_account "
|
||||
username := condition.Username
|
||||
values := make([]interface{}, 0)
|
||||
values := make([]any, 0)
|
||||
if username != "" {
|
||||
sql = sql + " WHERE username LIKE ?"
|
||||
values = append(values, "%"+username+"%")
|
||||
|
||||
@@ -13,7 +13,7 @@ func newConfigRepo() repository.Config {
|
||||
return new(configRepoImpl)
|
||||
}
|
||||
|
||||
func (m *configRepoImpl) GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (m *configRepoImpl) GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, condition, toEntity)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ func newMsgRepo() repository.Msg {
|
||||
return new(msgRepoImpl)
|
||||
}
|
||||
|
||||
func (m *msgRepoImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (m *msgRepoImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, condition, toEntity)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ func newResourceRepo() repository.Resource {
|
||||
return new(resourceRepoImpl)
|
||||
}
|
||||
|
||||
func (r *resourceRepoImpl) GetResourceList(condition *entity.Resource, toEntity interface{}, orderBy ...string) {
|
||||
func (r *resourceRepoImpl) GetResourceList(condition *entity.Resource, toEntity any, orderBy ...string) {
|
||||
model.ListByOrder(condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func (r *resourceRepoImpl) GetById(id uint64, cols ...string) *entity.Resource {
|
||||
return res
|
||||
}
|
||||
|
||||
func (r *resourceRepoImpl) GetByIdIn(ids []uint64, toEntity interface{}, orderBy ...string) {
|
||||
func (r *resourceRepoImpl) GetByIdIn(ids []uint64, toEntity any, orderBy ...string) {
|
||||
model.GetByIdIn(new(entity.Resource), toEntity, ids, orderBy...)
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func (r *resourceRepoImpl) GetByCondition(condition *entity.Resource, cols ...st
|
||||
return model.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
func (r *resourceRepoImpl) GetAccountResources(accountId uint64, toEntity interface{}) {
|
||||
func (r *resourceRepoImpl) GetAccountResources(accountId uint64, toEntity any) {
|
||||
sql := `SELECT
|
||||
m.id,
|
||||
m.pid,
|
||||
|
||||
@@ -13,7 +13,7 @@ func newRoleRepo() repository.Role {
|
||||
return new(roleRepoImpl)
|
||||
}
|
||||
|
||||
func (m *roleRepoImpl) GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (m *roleRepoImpl) GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ func (m *roleRepoImpl) GetRoleResourceIds(roleId uint64) []uint64 {
|
||||
return rids
|
||||
}
|
||||
|
||||
func (m *roleRepoImpl) GetRoleResources(roleId uint64, toEntity interface{}) {
|
||||
func (m *roleRepoImpl) GetRoleResources(roleId uint64, toEntity any) {
|
||||
sql := "select rr.creator AS creator, rr.create_time AS CreateTime, rr.resource_id AS id, r.pid AS pid, " +
|
||||
"r.name AS name, r.type AS type, r.status AS status " +
|
||||
"FROM t_sys_role_resource rr JOIN t_sys_resource r ON rr.resource_id = r.id " +
|
||||
@@ -74,7 +74,7 @@ func (m *roleRepoImpl) DeleteAccountRole(accountId, roleId uint64) {
|
||||
}
|
||||
|
||||
// 获取账号角色信息列表
|
||||
func (m *roleRepoImpl) GetAccountRoles(accountId uint64, toEntity interface{}) {
|
||||
func (m *roleRepoImpl) GetAccountRoles(accountId uint64, toEntity any) {
|
||||
sql := "SELECT r.status, r.name, ar.create_time AS CreateTime, ar.creator AS creator " +
|
||||
"FROM t_sys_role r JOIN t_sys_account_role ar ON r.id = ar.role_id AND ar.account_id = ? " +
|
||||
"ORDER BY ar.create_time DESC"
|
||||
|
||||
@@ -12,7 +12,7 @@ func newSyslogRepo() repository.Syslog {
|
||||
return new(syslogRepoImpl)
|
||||
}
|
||||
|
||||
func (m *syslogRepoImpl) GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (m *syslogRepoImpl) GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
|
||||
@@ -111,20 +111,20 @@ func (p *Team) SaveTags(rc *req.Ctx) {
|
||||
|
||||
teamId := form.TeamId
|
||||
|
||||
// 将[]uint64转为[]interface{}
|
||||
// 将[]uint64转为[]any
|
||||
oIds := p.TeamApp.ListTagIds(teamId)
|
||||
var oldIds []interface{}
|
||||
var oldIds []any
|
||||
for _, v := range oIds {
|
||||
oldIds = append(oldIds, v)
|
||||
}
|
||||
|
||||
var newIds []interface{}
|
||||
var newIds []any
|
||||
for _, v := range form.TagIds {
|
||||
newIds = append(newIds, v)
|
||||
}
|
||||
|
||||
// 比较新旧两合集
|
||||
addIds, delIds, _ := utils.ArrayCompare(newIds, oldIds, func(i1, i2 interface{}) bool {
|
||||
addIds, delIds, _ := utils.ArrayCompare(newIds, oldIds, func(i1, i2 any) bool {
|
||||
return i1.(uint64) == i2.(uint64)
|
||||
})
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
)
|
||||
|
||||
type TagTree interface {
|
||||
ListByQuery(condition *entity.TagTreeQuery, toEntity interface{})
|
||||
ListByQuery(condition *entity.TagTreeQuery, toEntity any)
|
||||
|
||||
GetById(id uint64) *entity.TagTree
|
||||
|
||||
@@ -96,7 +96,7 @@ func (p *tagTreeAppImpl) Save(tag *entity.TagTree) {
|
||||
p.tagTreeRepo.UpdateById(tag)
|
||||
}
|
||||
|
||||
func (p *tagTreeAppImpl) ListByQuery(condition *entity.TagTreeQuery, toEntity interface{}) {
|
||||
func (p *tagTreeAppImpl) ListByQuery(condition *entity.TagTreeQuery, toEntity any) {
|
||||
p.tagTreeRepo.SelectByCondition(condition, toEntity)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
type Team interface {
|
||||
// 分页获取项目团队信息列表
|
||||
GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
Save(team *entity.Team)
|
||||
|
||||
@@ -17,7 +17,7 @@ type Team interface {
|
||||
|
||||
//--------------- 团队成员相关接口 ---------------
|
||||
|
||||
GetMemberPage(condition *entity.TeamMember, pageParam *model.PageParam, toEntity interface{}) *model.PageResult
|
||||
GetMemberPage(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) *model.PageResult
|
||||
|
||||
SaveMember(tagTeamMember *entity.TeamMember)
|
||||
|
||||
@@ -51,7 +51,7 @@ type teamAppImpl struct {
|
||||
tagTreeTeamRepo repository.TagTreeTeam
|
||||
}
|
||||
|
||||
func (p *teamAppImpl) GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (p *teamAppImpl) GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return p.teamRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ func (p *teamAppImpl) Delete(id uint64) {
|
||||
|
||||
// --------------- 团队成员相关接口 ---------------
|
||||
|
||||
func (p *teamAppImpl) GetMemberPage(condition *entity.TeamMember, pageParam *model.PageParam, toEntity interface{}) *model.PageResult {
|
||||
func (p *teamAppImpl) GetMemberPage(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) *model.PageResult {
|
||||
return p.teamMemberRepo.GetPageList(condition, pageParam, toEntity)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
type TagTree interface {
|
||||
// 根据条件查询
|
||||
SelectByCondition(condition *entity.TagTreeQuery, toEntity interface{}, orderBy ...string)
|
||||
SelectByCondition(condition *entity.TagTreeQuery, toEntity any, orderBy ...string)
|
||||
|
||||
GetBy(condition *entity.TagTree, cols ...string) error
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import "mayfly-go/internal/tag/domain/entity"
|
||||
type TagTreeTeam interface {
|
||||
|
||||
// 获取团队标签信息列表
|
||||
ListTag(condition *entity.TagTreeTeam, toEntity interface{}, orderBy ...string)
|
||||
ListTag(condition *entity.TagTreeTeam, toEntity any, orderBy ...string)
|
||||
|
||||
Save(mp *entity.TagTreeTeam)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type Team interface {
|
||||
GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
|
||||
Insert(p *entity.Team)
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
type TeamMember interface {
|
||||
|
||||
// 获取项目成员列表
|
||||
ListMemeber(condition *entity.TeamMember, toEntity interface{}, orderBy ...string)
|
||||
ListMemeber(condition *entity.TeamMember, toEntity any, orderBy ...string)
|
||||
|
||||
Save(mp *entity.TeamMember)
|
||||
|
||||
GetPageList(condition *entity.TeamMember, pageParam *model.PageParam, toEntity interface{}) *model.PageResult
|
||||
GetPageList(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) *model.PageResult
|
||||
|
||||
DeleteBy(condition *entity.TeamMember)
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ func newTagTreeRepo() repository.TagTree {
|
||||
return new(tagTreeRepoImpl)
|
||||
}
|
||||
|
||||
func (p *tagTreeRepoImpl) SelectByCondition(condition *entity.TagTreeQuery, toEntity interface{}, orderBy ...string) {
|
||||
func (p *tagTreeRepoImpl) SelectByCondition(condition *entity.TagTreeQuery, toEntity any, orderBy ...string) {
|
||||
sql := "SELECT DISTINCT(p.id), p.pid, p.code, p.code_path, p.name, p.remark, p.create_time, p.creator, p.update_time, p.modifier FROM t_tag_tree p WHERE 1 = 1 "
|
||||
if condition.Name != "" {
|
||||
sql = sql + " AND p.name LIKE '%" + condition.Name + "%'"
|
||||
|
||||
@@ -13,7 +13,7 @@ func newTagTreeTeamRepo() repository.TagTreeTeam {
|
||||
return new(tagTreeTeamRepoImpl)
|
||||
}
|
||||
|
||||
func (p *tagTreeTeamRepoImpl) ListTag(condition *entity.TagTreeTeam, toEntity interface{}, orderBy ...string) {
|
||||
func (p *tagTreeTeamRepoImpl) ListTag(condition *entity.TagTreeTeam, toEntity any, orderBy ...string) {
|
||||
model.ListByOrder(condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ func newTeamRepo() repository.Team {
|
||||
return new(teamRepoImpl)
|
||||
}
|
||||
|
||||
func (p *teamRepoImpl) GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
func (p *teamRepoImpl) GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ func newTeamMemberRepo() repository.TeamMember {
|
||||
return new(teamMemberRepoImpl)
|
||||
}
|
||||
|
||||
func (p *teamMemberRepoImpl) ListMemeber(condition *entity.TeamMember, toEntity interface{}, orderBy ...string) {
|
||||
func (p *teamMemberRepoImpl) ListMemeber(condition *entity.TeamMember, toEntity any, orderBy ...string) {
|
||||
model.ListByOrder(condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func (p *teamMemberRepoImpl) Save(pm *entity.TeamMember) {
|
||||
biz.ErrIsNilAppendErr(model.Insert(pm), "保存团队成员失败:%s")
|
||||
}
|
||||
|
||||
func (p *teamMemberRepoImpl) GetPageList(condition *entity.TeamMember, pageParam *model.PageParam, toEntity interface{}) *model.PageResult {
|
||||
func (p *teamMemberRepoImpl) GetPageList(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) *model.PageResult {
|
||||
sql := "SELECT d.*, a.name FROM t_team_member d JOIN t_sys_account a ON d.account_id = a.id WHERE a.status = 1 "
|
||||
|
||||
if condition.AccountId != 0 {
|
||||
@@ -32,7 +32,7 @@ func (p *teamMemberRepoImpl) GetPageList(condition *entity.TeamMember, pageParam
|
||||
sql = fmt.Sprintf("%s AND d.team_id = %d", sql, condition.TeamId)
|
||||
}
|
||||
|
||||
values := make([]interface{}, 0)
|
||||
values := make([]any, 0)
|
||||
if condition.Username != "" {
|
||||
sql = sql + " AND d.Username LIKE ?"
|
||||
values = append(values, "%"+condition.Username+"%")
|
||||
|
||||
@@ -49,25 +49,25 @@ func NotEmpty(str string, msg string, params ...any) {
|
||||
}
|
||||
}
|
||||
|
||||
func NotNil(data interface{}, msg string, params ...any) {
|
||||
func NotNil(data any, msg string, params ...any) {
|
||||
if reflect.ValueOf(data).IsNil() {
|
||||
panic(NewBizErr(fmt.Sprintf(msg, params...)))
|
||||
}
|
||||
}
|
||||
|
||||
func NotBlank(data interface{}, msg string, params ...any) {
|
||||
func NotBlank(data any, msg string, params ...any) {
|
||||
if utils.IsBlank(data) {
|
||||
panic(NewBizErr(fmt.Sprintf(msg, params...)))
|
||||
}
|
||||
}
|
||||
|
||||
func IsEquals(data interface{}, data1 interface{}, msg string) {
|
||||
func IsEquals(data any, data1 any, msg string) {
|
||||
if data != data1 {
|
||||
panic(NewBizErr(msg))
|
||||
}
|
||||
}
|
||||
|
||||
func Nil(data interface{}, msg string) {
|
||||
func Nil(data any, msg string) {
|
||||
if !reflect.ValueOf(data).IsNil() {
|
||||
panic(NewBizErr(msg))
|
||||
}
|
||||
|
||||
8
server/pkg/cache/cache.go
vendored
8
server/pkg/cache/cache.go
vendored
@@ -2,17 +2,17 @@ package cache
|
||||
|
||||
type Cache interface {
|
||||
// 添加缓存,如果缓存则返回错误
|
||||
Add(k string, v interface{}) error
|
||||
Add(k string, v any) error
|
||||
|
||||
// 如果不存在则添加缓存值,否则直接返回
|
||||
AddIfAbsent(k string, v interface{})
|
||||
AddIfAbsent(k string, v any)
|
||||
|
||||
// 如果存在则直接返回,否则调用getValue回调函数获取值并添加该缓存值
|
||||
// @return 缓存值
|
||||
ComputeIfAbsent(k string, getValueFunc func(string) (interface{}, error)) (interface{}, error)
|
||||
ComputeIfAbsent(k string, getValueFunc func(string) (any, error)) (any, error)
|
||||
|
||||
// 获取缓存值,参数1为值,参数2->是否存在该缓存
|
||||
Get(k string) (interface{}, bool)
|
||||
Get(k string) (any, bool)
|
||||
|
||||
// 缓存数量
|
||||
Count() int
|
||||
|
||||
52
server/pkg/cache/timed_cache.go
vendored
52
server/pkg/cache/timed_cache.go
vendored
@@ -10,10 +10,10 @@ import (
|
||||
)
|
||||
|
||||
type Item struct {
|
||||
Value interface{} // 对象
|
||||
Expiration int64 // 缓存有效时间
|
||||
UseCount int64 // 使用次数
|
||||
AccessTime int64 // 访问时间
|
||||
Value any // 对象
|
||||
Expiration int64 // 缓存有效时间
|
||||
UseCount int64 // 使用次数
|
||||
AccessTime int64 // 访问时间
|
||||
}
|
||||
|
||||
// 是否过期
|
||||
@@ -26,7 +26,7 @@ func (item Item) Expired() bool {
|
||||
|
||||
// 是否过期
|
||||
// @return 值 and 是否过期
|
||||
func (item *Item) GetValue(updateAccessTime bool) (interface{}, bool) {
|
||||
func (item *Item) GetValue(updateAccessTime bool) (any, bool) {
|
||||
isExpired := item.Expired()
|
||||
// 更新最后访问时间,用于增加值的有效期
|
||||
if !isExpired && updateAccessTime {
|
||||
@@ -52,15 +52,15 @@ type TimedCache struct {
|
||||
type timedcache struct {
|
||||
defaultExpiration time.Duration
|
||||
updateAccessTime bool // 是否更新最后访问时间
|
||||
items map[interface{}]*Item
|
||||
items map[any]*Item
|
||||
mu sync.RWMutex
|
||||
onEvicted func(interface{}, interface{}) // 移除时回调函数
|
||||
onEvicted func(any, any) // 移除时回调函数
|
||||
janitor *janitor
|
||||
}
|
||||
|
||||
// Add an item to the cache only if an item doesn't already exist for the given
|
||||
// key, or if the existing item has expired. Returns an error otherwise.
|
||||
func (c *timedcache) Add(k interface{}, x interface{}, d time.Duration) error {
|
||||
func (c *timedcache) Add(k any, x any, d time.Duration) error {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
_, found := c.get(k)
|
||||
@@ -71,13 +71,13 @@ func (c *timedcache) Add(k interface{}, x interface{}, d time.Duration) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *timedcache) Put(k interface{}, x interface{}) {
|
||||
func (c *timedcache) Put(k any, x any) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
c.set(k, x, c.defaultExpiration)
|
||||
}
|
||||
|
||||
func (c *timedcache) AddIfAbsent(k interface{}, x interface{}) {
|
||||
func (c *timedcache) AddIfAbsent(k any, x any) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
_, found := c.get(k)
|
||||
@@ -87,7 +87,7 @@ func (c *timedcache) AddIfAbsent(k interface{}, x interface{}) {
|
||||
c.set(k, x, c.defaultExpiration)
|
||||
}
|
||||
|
||||
func (c *timedcache) ComputeIfAbsent(k interface{}, getValueFunc func(interface{}) (interface{}, error)) (interface{}, error) {
|
||||
func (c *timedcache) ComputeIfAbsent(k any, getValueFunc func(any) (any, error)) (any, error) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
value, found := c.get(k)
|
||||
@@ -103,7 +103,7 @@ func (c *timedcache) ComputeIfAbsent(k interface{}, getValueFunc func(interface{
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func (c *timedcache) set(k interface{}, x interface{}, d time.Duration) {
|
||||
func (c *timedcache) set(k any, x any, d time.Duration) {
|
||||
var e int64
|
||||
if d == DefaultExpiration {
|
||||
d = c.defaultExpiration
|
||||
@@ -120,13 +120,13 @@ func (c *timedcache) set(k interface{}, x interface{}, d time.Duration) {
|
||||
|
||||
// Get an item from the cache. Returns the item or nil, and a bool indicating
|
||||
// whether the key was found.
|
||||
func (c *timedcache) Get(k interface{}) (interface{}, bool) {
|
||||
func (c *timedcache) Get(k any) (any, bool) {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
return c.get(k)
|
||||
}
|
||||
|
||||
func (c *timedcache) get(k interface{}) (interface{}, bool) {
|
||||
func (c *timedcache) get(k any) (any, bool) {
|
||||
item, found := c.items[k]
|
||||
if !found {
|
||||
return nil, false
|
||||
@@ -145,7 +145,7 @@ func (c *timedcache) get(k interface{}) (interface{}, bool) {
|
||||
// item's value is not an integer, if it was not found, or if it is not
|
||||
// possible to increment it by n. To retrieve the incremented value, use one
|
||||
// of the specialized methods, e.g. IncrementInt64.
|
||||
func (c *timedcache) Increment(k interface{}, n int64) error {
|
||||
func (c *timedcache) Increment(k any, n int64) error {
|
||||
c.mu.Lock()
|
||||
v, found := c.items[k]
|
||||
if !found || v.Expired() {
|
||||
@@ -198,10 +198,10 @@ func (c *timedcache) Count() int {
|
||||
}
|
||||
|
||||
// Copies all unexpired items in the cache into a new map and returns it.
|
||||
func (c *timedcache) Items() map[interface{}]*Item {
|
||||
func (c *timedcache) Items() map[any]*Item {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
m := make(map[interface{}]*Item, len(c.items))
|
||||
m := make(map[any]*Item, len(c.items))
|
||||
now := time.Now().UnixNano()
|
||||
for k, v := range c.items {
|
||||
// "Inlining" of Expired
|
||||
@@ -216,7 +216,7 @@ func (c *timedcache) Items() map[interface{}]*Item {
|
||||
}
|
||||
|
||||
// 删除指定key的数据
|
||||
func (c *timedcache) Delete(k interface{}) {
|
||||
func (c *timedcache) Delete(k any) {
|
||||
c.mu.Lock()
|
||||
v, evicted := c.delete(k)
|
||||
c.mu.Unlock()
|
||||
@@ -225,7 +225,7 @@ func (c *timedcache) Delete(k interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *timedcache) delete(k interface{}) (interface{}, bool) {
|
||||
func (c *timedcache) delete(k any) (any, bool) {
|
||||
// 如果有移除回调函数,则返回值及是否有删除回调函数用于进行回调处理
|
||||
if c.onEvicted != nil {
|
||||
if v, found := c.items[k]; found {
|
||||
@@ -238,8 +238,8 @@ func (c *timedcache) delete(k interface{}) (interface{}, bool) {
|
||||
}
|
||||
|
||||
type keyAndValue struct {
|
||||
key interface{}
|
||||
value interface{}
|
||||
key any
|
||||
value any
|
||||
}
|
||||
|
||||
// Delete all expired items from the cache.
|
||||
@@ -265,7 +265,7 @@ func (c *timedcache) DeleteExpired() {
|
||||
// 清空所有缓存
|
||||
func (c *timedcache) Clear() {
|
||||
c.mu.Lock()
|
||||
c.items = map[interface{}]*Item{}
|
||||
c.items = map[any]*Item{}
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
@@ -378,7 +378,7 @@ func runJanitor(c *timedcache, ci time.Duration) {
|
||||
go j.Run(c)
|
||||
}
|
||||
|
||||
func newCache(de time.Duration, m map[interface{}]*Item) *timedcache {
|
||||
func newCache(de time.Duration, m map[any]*Item) *timedcache {
|
||||
if de == 0 {
|
||||
de = -1
|
||||
}
|
||||
@@ -389,7 +389,7 @@ func newCache(de time.Duration, m map[interface{}]*Item) *timedcache {
|
||||
return c
|
||||
}
|
||||
|
||||
func newCacheWithJanitor(de time.Duration, ci time.Duration, m map[interface{}]*Item) *TimedCache {
|
||||
func newCacheWithJanitor(de time.Duration, ci time.Duration, m map[any]*Item) *TimedCache {
|
||||
c := newCache(de, m)
|
||||
// This trick ensures that the janitor goroutine (which--granted it
|
||||
// was enabled--is running DeleteExpired on c forever) does not keep
|
||||
@@ -410,12 +410,12 @@ func newCacheWithJanitor(de time.Duration, ci time.Duration, m map[interface{}]*
|
||||
// manually. If the cleanup interval is less than one, expired items are not
|
||||
// deleted from the cache before calling c.DeleteExpired().
|
||||
func NewTimedCache(defaultExpiration, cleanupInterval time.Duration) *TimedCache {
|
||||
items := make(map[interface{}]*Item)
|
||||
items := make(map[any]*Item)
|
||||
return newCacheWithJanitor(defaultExpiration, cleanupInterval, items)
|
||||
}
|
||||
|
||||
// 调用删除函数时,会回调该剔除函数
|
||||
func (c *TimedCache) OnEvicted(f func(interface{}, interface{})) *TimedCache {
|
||||
func (c *TimedCache) OnEvicted(f func(any, any)) *TimedCache {
|
||||
c.mu.Lock()
|
||||
c.onEvicted = f
|
||||
c.mu.Unlock()
|
||||
|
||||
@@ -13,14 +13,14 @@ import (
|
||||
)
|
||||
|
||||
// 绑定并校验请求结构体参数
|
||||
func BindJsonAndValid(g *gin.Context, data interface{}) {
|
||||
func BindJsonAndValid(g *gin.Context, data any) {
|
||||
if err := g.ShouldBindJSON(data); err != nil {
|
||||
panic(biz.NewBizErr(err.Error()))
|
||||
}
|
||||
}
|
||||
|
||||
// 绑定查询字符串到
|
||||
func BindQuery(g *gin.Context, data interface{}) {
|
||||
func BindQuery(g *gin.Context, data any) {
|
||||
if err := g.ShouldBindQuery(data); err != nil {
|
||||
panic(biz.NewBizErr(err.Error()))
|
||||
}
|
||||
@@ -65,12 +65,12 @@ func Download(g *gin.Context, reader io.Reader, filename string) {
|
||||
}
|
||||
|
||||
// 返回统一成功结果
|
||||
func SuccessRes(g *gin.Context, data interface{}) {
|
||||
func SuccessRes(g *gin.Context, data any) {
|
||||
g.JSON(http.StatusOK, model.Success(data))
|
||||
}
|
||||
|
||||
// 返回失败结果集
|
||||
func ErrorRes(g *gin.Context, err interface{}) {
|
||||
func ErrorRes(g *gin.Context, err any) {
|
||||
switch t := err.(type) {
|
||||
case biz.BizError:
|
||||
g.JSON(http.StatusOK, model.Error(t))
|
||||
|
||||
@@ -86,7 +86,7 @@ func (r *RequestWrapper) PostJson(body string) *ResponseWrapper {
|
||||
return request(r)
|
||||
}
|
||||
|
||||
func (r *RequestWrapper) PostObj(body interface{}) *ResponseWrapper {
|
||||
func (r *RequestWrapper) PostObj(body any) *ResponseWrapper {
|
||||
marshal, err := json.Marshal(body)
|
||||
if err != nil {
|
||||
return createRequestError(errors.New("解析json obj错误"))
|
||||
@@ -158,7 +158,7 @@ func (r *ResponseWrapper) IsSuccess() bool {
|
||||
return r.StatusCode == 200
|
||||
}
|
||||
|
||||
func (r *ResponseWrapper) BodyToObj(objPtr interface{}) error {
|
||||
func (r *ResponseWrapper) BodyToObj(objPtr any) error {
|
||||
_ = json.Unmarshal(r.Body, &objPtr)
|
||||
return r.getError()
|
||||
}
|
||||
@@ -167,8 +167,8 @@ func (r *ResponseWrapper) BodyToString() (string, error) {
|
||||
return string(r.Body), r.getError()
|
||||
}
|
||||
|
||||
func (r *ResponseWrapper) BodyToMap() (map[string]interface{}, error) {
|
||||
var res map[string]interface{}
|
||||
func (r *ResponseWrapper) BodyToMap() (map[string]any, error) {
|
||||
var res map[string]any
|
||||
err := json.Unmarshal(r.Body, &res)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -67,13 +67,13 @@ func Tx(funcs ...func(db *gorm.DB) error) (err error) {
|
||||
//
|
||||
// 若error不为nil则为不存在该记录
|
||||
// @param model 数据库映射实体模型
|
||||
func GetById(model interface{}, id uint64, cols ...string) error {
|
||||
func GetById(model any, id uint64, cols ...string) error {
|
||||
return global.Db.Select(cols).Where("id = ?", id).First(model).Error
|
||||
}
|
||||
|
||||
// 根据map条件查询列表,map中的值如果为数组,则使用in查询
|
||||
// @param model 数据库映射实体模型
|
||||
func GetByIdIn(model interface{}, list interface{}, ids []uint64, orderBy ...string) {
|
||||
func GetByIdIn(model any, list any, ids []uint64, orderBy ...string) {
|
||||
var orderByStr string
|
||||
if orderBy == nil {
|
||||
orderByStr = "id desc"
|
||||
@@ -84,7 +84,7 @@ func GetByIdIn(model interface{}, list interface{}, ids []uint64, orderBy ...str
|
||||
}
|
||||
|
||||
// 根据map指定条件查询列表
|
||||
func SelectByMap(model interface{}, list interface{}, where map[string]interface{}, orderBy ...string) {
|
||||
func SelectByMap(model any, list any, where map[string]any, orderBy ...string) {
|
||||
var orderByStr string
|
||||
if orderBy == nil {
|
||||
orderByStr = "id desc"
|
||||
@@ -95,7 +95,7 @@ func SelectByMap(model interface{}, list interface{}, where map[string]interface
|
||||
}
|
||||
|
||||
// 根据model指定条件统计数量
|
||||
func CountBy(model interface{}) int64 {
|
||||
func CountBy(model any) int64 {
|
||||
var count int64
|
||||
global.Db.Model(model).Where(model).Count(&count)
|
||||
return count
|
||||
@@ -104,7 +104,7 @@ func CountBy(model interface{}) int64 {
|
||||
// 根据map为条件统计数量,map中的值如果为数组,则使用in查询
|
||||
// @param model 数据库映射实体模型
|
||||
// @param where 条件map
|
||||
func CountByMap(model interface{}, where map[string]interface{}) int64 {
|
||||
func CountByMap(model any, where map[string]any) int64 {
|
||||
var count int64
|
||||
global.Db.Model(model).Where(where).Count(&count)
|
||||
return count
|
||||
@@ -119,32 +119,32 @@ func CountBySql(sql string) int64 {
|
||||
|
||||
// 根据id更新model,更新字段为model中不为空的值,即int类型不为0,ptr类型不为nil这类字段值
|
||||
// @param model 数据库映射实体模型
|
||||
func UpdateById(model interface{}) error {
|
||||
func UpdateById(model any) error {
|
||||
return global.Db.Model(model).Updates(model).Error
|
||||
}
|
||||
|
||||
// 根据id删除model
|
||||
// @param model 数据库映射实体模型
|
||||
func DeleteById(model interface{}, id uint64) error {
|
||||
func DeleteById(model any, id uint64) error {
|
||||
return global.Db.Delete(model, "id = ?", id).Error
|
||||
}
|
||||
|
||||
// 根据条件删除
|
||||
// @param model 数据库映射实体模型
|
||||
func DeleteByCondition(model interface{}) error {
|
||||
func DeleteByCondition(model any) error {
|
||||
return global.Db.Where(model).Delete(model).Error
|
||||
}
|
||||
|
||||
// 插入model
|
||||
// @param model 数据库映射实体模型
|
||||
func Insert(model interface{}) error {
|
||||
func Insert(model any) error {
|
||||
return global.Db.Create(model).Error
|
||||
}
|
||||
|
||||
// 获取满足model中不为空的字段值条件的所有数据.
|
||||
//
|
||||
// @param list为数组类型 如 var users *[]User,可指定为非model结构体,即只包含需要返回的字段结构体
|
||||
func ListBy(model interface{}, list interface{}, cols ...string) {
|
||||
func ListBy(model any, list any, cols ...string) {
|
||||
global.Db.Model(model).Select(cols).Where(model).Order("id desc").Find(list)
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ func ListBy(model interface{}, list interface{}, cols ...string) {
|
||||
//
|
||||
// @param list为数组类型 如 var users *[]User,可指定为非model结构体
|
||||
// @param model 数据库映射实体模型
|
||||
func ListByOrder(model interface{}, list interface{}, order ...string) {
|
||||
func ListByOrder(model any, list any, order ...string) {
|
||||
var orderByStr string
|
||||
if order == nil {
|
||||
orderByStr = "id desc"
|
||||
@@ -166,7 +166,7 @@ func ListByOrder(model interface{}, list interface{}, order ...string) {
|
||||
//
|
||||
// 若 error不为nil,则为不存在该记录
|
||||
// @param model 数据库映射实体模型
|
||||
func GetBy(model interface{}, cols ...string) error {
|
||||
func GetBy(model any, cols ...string) error {
|
||||
return global.Db.Select(cols).Where(model).First(model).Error
|
||||
}
|
||||
|
||||
@@ -175,12 +175,12 @@ func GetBy(model interface{}, cols ...string) error {
|
||||
// @param toModel 需要查询的字段
|
||||
//
|
||||
// 若 error不为nil,则为不存在该记录
|
||||
func GetByConditionTo(conditionModel interface{}, toModel interface{}) error {
|
||||
func GetByConditionTo(conditionModel any, toModel any) error {
|
||||
return global.Db.Model(conditionModel).Where(conditionModel).First(toModel).Error
|
||||
}
|
||||
|
||||
// 获取分页结果
|
||||
func GetPage(pageParam *PageParam, model interface{}, conditionModel interface{}, toModels interface{}, orderBy ...string) *PageResult {
|
||||
func GetPage(pageParam *PageParam, model any, conditionModel any, toModels any, orderBy ...string) *PageResult {
|
||||
var count int64
|
||||
err := global.Db.Model(model).Where(conditionModel).Count(&count).Error
|
||||
biz.ErrIsNilAppendErr(err, " 查询错误:%s")
|
||||
@@ -202,7 +202,7 @@ func GetPage(pageParam *PageParam, model interface{}, conditionModel interface{}
|
||||
}
|
||||
|
||||
// 根据sql获取分页对象
|
||||
func GetPageBySql(sql string, param *PageParam, toModel interface{}, args ...interface{}) *PageResult {
|
||||
func GetPageBySql(sql string, param *PageParam, toModel any, args ...any) *PageResult {
|
||||
db := global.Db
|
||||
selectIndex := strings.Index(sql, "SELECT ") + 7
|
||||
fromIndex := strings.Index(sql, " FROM")
|
||||
@@ -222,12 +222,12 @@ func GetPageBySql(sql string, param *PageParam, toModel interface{}, args ...int
|
||||
return &PageResult{Total: int64(count), List: toModel}
|
||||
}
|
||||
|
||||
func GetListBySql(sql string, params ...interface{}) []map[string]interface{} {
|
||||
var maps []map[string]interface{}
|
||||
func GetListBySql(sql string, params ...any) []map[string]any {
|
||||
var maps []map[string]any
|
||||
global.Db.Raw(sql, params...).Scan(&maps)
|
||||
return maps
|
||||
}
|
||||
|
||||
func GetListBySql2Model(sql string, toEntity interface{}, params ...interface{}) error {
|
||||
func GetListBySql2Model(sql string, toEntity any, params ...any) error {
|
||||
return global.Db.Raw(sql, params...).Find(toEntity).Error
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@ const (
|
||||
|
||||
// 统一返回结果结构体
|
||||
type Result struct {
|
||||
Code int16 `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data interface{} `json:"data"`
|
||||
Code int16 `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data any `json:"data"`
|
||||
}
|
||||
|
||||
// 将Result转为json字符串
|
||||
@@ -34,7 +34,7 @@ func (r *Result) IsSuccess() bool {
|
||||
|
||||
// 返回成功状态的Result
|
||||
// @param data 成功附带的数据消息
|
||||
func Success(data interface{}) *Result {
|
||||
func Success(data any) *Result {
|
||||
return &Result{Code: SuccessCode, Msg: SuccessMsg, Data: data}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ func Del(key string) {
|
||||
cli.Del(context.TODO(), key)
|
||||
}
|
||||
|
||||
func HSet(key string, field string, val interface{}) {
|
||||
func HSet(key string, field string, val any) {
|
||||
cli.HSet(context.TODO(), key, field, val)
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ func getLogMsg(rc *Ctx) string {
|
||||
return msg
|
||||
}
|
||||
|
||||
func getErrMsg(rc *Ctx, err interface{}) string {
|
||||
func getErrMsg(rc *Ctx, err any) string {
|
||||
msg := rc.LogInfo.Description
|
||||
if !utils.IsBlank(rc.ReqParam) {
|
||||
msg = msg + fmt.Sprintf("\n--> %s", utils.ToString(rc.ReqParam))
|
||||
|
||||
@@ -106,7 +106,7 @@ func UseAfterHandlerInterceptor(b HandlerInterceptorFunc) {
|
||||
}
|
||||
|
||||
// 应用指定处理器拦截器,如果有一个错误则直接返回错误
|
||||
func ApplyHandlerInterceptor(his HandlerInterceptors, rc *Ctx) interface{} {
|
||||
func ApplyHandlerInterceptor(his HandlerInterceptors, rc *Ctx) any {
|
||||
for _, handler := range his {
|
||||
if err := handler(rc); err != nil {
|
||||
return err
|
||||
|
||||
@@ -50,7 +50,7 @@ func ParseToken(tokenStr string) (*model.LoginAccount, error) {
|
||||
return nil, errors.New("token error")
|
||||
}
|
||||
// Parse token
|
||||
token, err := jwt.Parse(tokenStr, func(token *jwt.Token) (interface{}, error) {
|
||||
token, err := jwt.Parse(tokenStr, func(token *jwt.Token) (any, error) {
|
||||
return []byte(JwtKey), nil
|
||||
})
|
||||
if err != nil || token == nil {
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
|
||||
// 数组比较
|
||||
// 依次返回,新增值,删除值,以及不变值
|
||||
func ArrayCompare(newArr []interface{}, oldArr []interface{}, compareFun func(interface{}, interface{}) bool) ([]interface{}, []interface{}, []interface{}) {
|
||||
var unmodifierValue []interface{}
|
||||
func ArrayCompare(newArr []any, oldArr []any, compareFun func(any, any) bool) ([]any, []any, []any) {
|
||||
var unmodifierValue []any
|
||||
ni, oi := 0, 0
|
||||
for {
|
||||
if ni >= len(newArr) {
|
||||
|
||||
@@ -6,9 +6,9 @@ import (
|
||||
)
|
||||
|
||||
func TestArrayCompare(t *testing.T) {
|
||||
newArr := []interface{}{1, 2, 3, 5}
|
||||
oldArr := []interface{}{3, 6}
|
||||
add, del, unmodifier := ArrayCompare(newArr, oldArr, func(i1, i2 interface{}) bool {
|
||||
newArr := []any{1, 2, 3, 5}
|
||||
oldArr := []any{3, 6}
|
||||
add, del, unmodifier := ArrayCompare(newArr, oldArr, func(i1, i2 any) bool {
|
||||
return i1.(int) == i2.(int)
|
||||
})
|
||||
fmt.Println(add...)
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"mayfly-go/pkg/global"
|
||||
)
|
||||
|
||||
func Json2Map(jsonStr string) map[string]interface{} {
|
||||
var res map[string]interface{}
|
||||
func Json2Map(jsonStr string) map[string]any {
|
||||
var res map[string]any
|
||||
if jsonStr == "" {
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func GetString4Map(m map[string]interface{}, key string) string {
|
||||
func GetString4Map(m map[string]any, key string) string {
|
||||
return m[key].(string)
|
||||
}
|
||||
|
||||
func GetInt4Map(m map[string]interface{}, key string) int {
|
||||
func GetInt4Map(m map[string]any, key string) int {
|
||||
i := m[key]
|
||||
iKind := reflect.TypeOf(i).Kind()
|
||||
if iKind == reflect.Int {
|
||||
@@ -24,21 +24,21 @@ func GetInt4Map(m map[string]interface{}, key string) int {
|
||||
|
||||
// map构造器
|
||||
type mapBuilder struct {
|
||||
m map[string]interface{}
|
||||
m map[string]any
|
||||
}
|
||||
|
||||
func MapBuilder(key string, value interface{}) *mapBuilder {
|
||||
func MapBuilder(key string, value any) *mapBuilder {
|
||||
mb := new(mapBuilder)
|
||||
mb.m = make(map[string]interface{}, 4)
|
||||
mb.m = make(map[string]any, 4)
|
||||
mb.m[key] = value
|
||||
return mb
|
||||
}
|
||||
|
||||
func (mb *mapBuilder) Put(key string, value interface{}) *mapBuilder {
|
||||
func (mb *mapBuilder) Put(key string, value any) *mapBuilder {
|
||||
mb.m[key] = value
|
||||
return mb
|
||||
}
|
||||
|
||||
func (mb *mapBuilder) ToMap() map[string]interface{} {
|
||||
func (mb *mapBuilder) ToMap() map[string]any {
|
||||
return mb.m
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user