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
567e68b3
authored
Jun 25, 2024
by
岳巧源
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add get api list from mongodb
parent
94e0d6d4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
100 additions
and
14 deletions
go.mod
go.sum
internal/consts/consts.go
internal/service/apiList.go
manifest/config/config.toml
go.mod
View file @
567e68b3
...
...
@@ -2,4 +2,7 @@ module dev-ops
go 1.15
require github.com/gogf/gf/v2 v2.1.1
require (
github.com/gogf/gf/v2 v2.1.1
go.mongodb.org/mongo-driver v1.10.6
)
go.sum
View file @
567e68b3
This diff is collapsed.
Click to expand it.
internal/consts/consts.go
View file @
567e68b3
...
...
@@ -9,4 +9,5 @@ const (
API_INTERFACE_MINCALLMAX_STATISTICS_KEY
=
"api_apiKey_interface_minCallMax_key"
// 接口每天统计情况redisKey
API_INTERFACE_DAYCALL_STATISTICS_KEY
=
"api_apiKey_interface_dayCall_statistics"
OPEN_PLATFORM_GROUP_ID
=
337
)
internal/service/apiList.go
View file @
567e68b3
...
...
@@ -7,16 +7,19 @@ import (
"dev-ops/utility/response"
"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/frame/g"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"strings"
"time"
)
type
InterfaceNameInfo
struct
{
InterfaceName
string
Version
string
URI
string
Method
string
DayCallNum
int
InterfaceName
string
`json:"interface_name"`
Version
string
`json:"version"`
URI
string
`json:"uri"`
Method
string
`json:"method"`
DayCallNum
int
`json:"day_call_num"`
}
type
sApiList
struct
{}
...
...
@@ -34,13 +37,11 @@ func (s *sApiList) GetApiList(ctx context.Context, req *v1.ApiListReq) (interfac
if
param
[
"page"
]
!=
0
{
}
//mongodb数据源
item
:=
InterfaceNameInfo
{
InterfaceName
:
"查询标准品牌"
,
Version
:
"v1"
,
URI
:
"/brand/getStandardBrandList"
,
Method
:
"GET"
,
interfaceNameInfoList
,
err
:=
GetInterfaceNameListFromYapi
(
ctx
)
if
err
!=
nil
{
//无法从mongodb中获取完整接口列表
return
nil
,
response
.
CodeInternal
}
interfaceNameInfoList
:=
[]
InterfaceNameInfo
{
item
}
for
i
:=
0
;
i
<
len
(
interfaceNameInfoList
);
i
++
{
interfaceNameInfoList
[
i
]
.
DayCallNum
=
GetNumsByInterfaceName
(
ctx
,
interfaceNameInfoList
[
i
]
.
URI
)
}
...
...
@@ -85,3 +86,47 @@ func GetNumsByApiKey(ctx context.Context, apiKey string, interfaceNames []string
}
return
res
}
func
GetInterfaceNameListFromYapi
(
ctx
context
.
Context
)
([]
InterfaceNameInfo
,
error
)
{
interfaceNameInfoList
:=
make
([]
InterfaceNameInfo
,
0
)
address
,
_
:=
g
.
Cfg
()
.
Get
(
ctx
,
"mongodb.address"
)
client
,
err
:=
mongo
.
Connect
(
ctx
,
options
.
Client
()
.
ApplyURI
(
address
.
String
()))
if
err
!=
nil
{
return
nil
,
err
}
if
err
:=
client
.
Ping
(
ctx
,
nil
);
err
!=
nil
{
return
nil
,
err
}
cur
,
err
:=
client
.
Database
(
"yapi"
)
.
Collection
(
"project"
)
.
Find
(
ctx
,
bson
.
D
{{
"group_id"
,
consts
.
OPEN_PLATFORM_GROUP_ID
}})
if
err
!=
nil
{
return
nil
,
err
}
var
resultsOfProject
[]
bson
.
M
var
projectIds
[]
int32
=
[]
int32
{}
if
err
:=
cur
.
All
(
ctx
,
&
resultsOfProject
);
err
!=
nil
{
return
nil
,
err
}
for
_
,
result
:=
range
resultsOfProject
{
id
,
_
:=
result
[
"_id"
]
.
(
int32
)
projectIds
=
append
(
projectIds
,
id
)
}
for
_
,
projectId
:=
range
projectIds
{
var
resultsOfInterface
[]
bson
.
M
cursor
,
err
:=
client
.
Database
(
"yapi"
)
.
Collection
(
"interface"
)
.
Find
(
ctx
,
bson
.
D
{{
"project_id"
,
projectId
}})
if
err
!=
nil
{
return
nil
,
err
}
if
err
:=
cursor
.
All
(
ctx
,
&
resultsOfInterface
);
err
!=
nil
{
return
nil
,
err
}
for
_
,
result
:=
range
resultsOfInterface
{
interfaceNameInfo
:=
InterfaceNameInfo
{}
interfaceNameInfo
.
InterfaceName
,
_
=
result
[
"title"
]
.
(
string
)
interfaceNameInfo
.
Version
=
"v1"
interfaceNameInfo
.
URI
,
_
=
result
[
"path"
]
.
(
string
)
interfaceNameInfo
.
Method
,
_
=
result
[
"method"
]
.
(
string
)
interfaceNameInfoList
=
append
(
interfaceNameInfoList
,
interfaceNameInfo
)
}
}
return
interfaceNameInfoList
,
nil
}
manifest/config/config.toml
View file @
567e68b3
...
...
@@ -10,3 +10,5 @@
pass
=
"icDb29mLy2s"
[mongodb]
address
=
"mongodb://yapi:yapi231@192.168.1.237:27017/yapi"
\ No newline at end of file
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