Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
open-source
/
dev-ops
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e80a94c3
authored
Jun 25, 2024
by
岳巧源
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add split page
parent
567e68b3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
10 deletions
api/v1/apiList.go
internal/service/apiList.go
api/v1/apiList.go
View file @
e80a94c3
...
...
@@ -4,9 +4,10 @@ import "github.com/gogf/gf/v2/frame/g"
type
ApiListReq
struct
{
g
.
Meta
`path:"/api/list" method:"get" summary:"查询api列表"`
Page
string
`json:"page" d:"1" dc:"请输入第几页,不传默认第1页"`
Limit
string
`json:"limit" d:"10" dc:"每页限制个数"`
OffsetTime
int64
`json:"offset_time" dc:"offset_time为时间戳"`
Page
int
`json:"page" d:"1" dc:"请输入第几页,不传默认第1页"`
Limit
int
`json:"limit" d:"50" dc:"每页限制个数"`
Sort
bool
`json:"sort" d:"false" dc:"按照调用次数从多到少排序"`
OffsetTime
int64
`json:"offset_time" dc:"offset_time为时间戳"`
}
type
ApiListRes
struct
{
...
...
internal/service/apiList.go
View file @
e80a94c3
...
...
@@ -10,6 +10,8 @@ import (
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"math"
"sort"
"strings"
"time"
)
...
...
@@ -29,13 +31,6 @@ func ApiList() *sApiList {
}
func
(
s
*
sApiList
)
GetApiList
(
ctx
context
.
Context
,
req
*
v1
.
ApiListReq
)
(
interface
{},
gcode
.
Code
)
{
param
:=
map
[
string
]
interface
{}{
"page"
:
req
.
Page
,
"limit"
:
req
.
Limit
,
"offset_time"
:
req
.
OffsetTime
,
}
if
param
[
"page"
]
!=
0
{
}
//mongodb数据源
interfaceNameInfoList
,
err
:=
GetInterfaceNameListFromYapi
(
ctx
)
if
err
!=
nil
{
...
...
@@ -45,6 +40,26 @@ func (s *sApiList) GetApiList(ctx context.Context, req *v1.ApiListReq) (interfac
for
i
:=
0
;
i
<
len
(
interfaceNameInfoList
);
i
++
{
interfaceNameInfoList
[
i
]
.
DayCallNum
=
GetNumsByInterfaceName
(
ctx
,
interfaceNameInfoList
[
i
]
.
URI
)
}
var
sortByCallNums
bool
=
req
.
Sort
if
sortByCallNums
{
sort
.
Slice
(
interfaceNameInfoList
,
func
(
i
,
j
int
)
bool
{
return
interfaceNameInfoList
[
i
]
.
DayCallNum
>
interfaceNameInfoList
[
j
]
.
DayCallNum
})
}
//分页查询
page
:=
req
.
Page
limit
:=
req
.
Limit
if
limit
>
0
&&
page
>
0
&&
limit
<
len
(
interfaceNameInfoList
)
{
maxPageNum
:=
int
(
math
.
Ceil
(
float64
(
len
(
interfaceNameInfoList
))
/
float64
(
limit
)))
if
page
<=
maxPageNum
{
start
:=
(
page
-
1
)
*
limit
end
:=
page
*
limit
if
end
>
len
(
interfaceNameInfoList
)
{
end
=
len
(
interfaceNameInfoList
)
}
interfaceNameInfoList
=
interfaceNameInfoList
[
start
:
end
]
}
}
return
interfaceNameInfoList
,
response
.
CodeSuccess
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment