Skip to content

Commit ba52dd1

Browse files
Merge pull request #2454 from actiontech/issue-101-1
sqle支持获取swagger文件
2 parents 4c43029 + 5c28856 commit ba52dd1

40 files changed

+17
-8284
lines changed

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ require (
5858
github.com/sirupsen/logrus v1.9.0
5959
github.com/spf13/cobra v1.1.1
6060
github.com/stretchr/testify v1.8.4
61-
github.com/swaggo/echo-swagger v1.0.0
6261
github.com/swaggo/swag v1.6.7
6362
github.com/ungerik/go-dry v0.0.0-20210209114055-a3e162a9e62e
6463
github.com/urfave/cli/v2 v2.8.1
@@ -154,7 +153,6 @@ require (
154153
github.com/siddontang/go-log v0.0.0-20180807004314-8d05993dda07 // indirect
155154
github.com/skeema/knownhosts v1.2.0 // indirect
156155
github.com/spf13/pflag v1.0.5 // indirect
157-
github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14 // indirect
158156
github.com/tjfoc/gmsm v1.4.1 // indirect
159157
github.com/valyala/bytebufferpool v1.0.0 // indirect
160158
github.com/valyala/fasttemplate v1.2.2 // indirect

go.sum

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -577,13 +577,11 @@ github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czP
577577
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
578578
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
579579
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
580-
github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
581580
github.com/mailru/easyjson v0.7.1 h1:mdxE1MF9o53iCb2Ghj1VfWvh7ZOwHpnVG/xwXrV90U8=
582581
github.com/mailru/easyjson v0.7.1/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
583582
github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A=
584583
github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
585584
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
586-
github.com/mattn/go-colorable v0.1.0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
587585
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
588586
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
589587
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
@@ -877,11 +875,7 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
877875
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
878876
github.com/struCoder/pidusage v0.1.2/go.mod h1:pWBlW3YuSwRl6h7R5KbvA4N8oOqe9LjaKW5CwT1SPjI=
879877
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
880-
github.com/swaggo/echo-swagger v1.0.0 h1:ppQFt6Am3/MHIUmTpZOwi4gggMZ/W9zmKP4Z9ahTe5c=
881-
github.com/swaggo/echo-swagger v1.0.0/go.mod h1:Vnz3c2TGeFpoZPSV3CkWCrvyfU0016Gq/S0j4JspQnM=
882-
github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14 h1:PyYN9JH5jY9j6av01SpfRMb+1DWg/i3MbGOKPxJ2wjM=
883878
github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14/go.mod h1:gxQT6pBGRuIGunNf/+tSOB5OHvguWi8Tbt82WOkf35E=
884-
github.com/swaggo/gin-swagger v1.2.0 h1:YskZXEiv51fjOMTsXrOetAjrMDfFaXD79PEoQBOe2W0=
885879
github.com/swaggo/gin-swagger v1.2.0/go.mod h1:qlH2+W7zXGZkczuL+r2nEBR2JTT+/lX05Nn6vPhc7OI=
886880
github.com/swaggo/http-swagger v0.0.0-20200103000832-0e9263c4b516/go.mod h1:O1lAbCgAAX/KZ80LM/OXwtWFI/5TvZlwxSg8Cq08PV0=
887881
github.com/swaggo/http-swagger v0.0.0-20200308142732-58ac5e232fba/go.mod h1:O1lAbCgAAX/KZ80LM/OXwtWFI/5TvZlwxSg8Cq08PV0=
@@ -1087,7 +1081,6 @@ golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLL
10871081
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
10881082
golang.org/x/net v0.0.0-20190909003024-a7b16738d86b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
10891083
golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
1090-
golang.org/x/net v0.0.0-20191204025024-5ee1b9f4859a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
10911084
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
10921085
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
10931086
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
@@ -1244,7 +1237,6 @@ golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtn
12441237
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
12451238
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
12461239
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
1247-
golang.org/x/tools v0.0.0-20191205060818-73c7173a9f7d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
12481240
golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
12491241
golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
12501242
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=

sqle/api/app.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/facebookgo/grace/gracenet"
2323
"github.com/labstack/echo/v4"
2424
"github.com/labstack/echo/v4/middleware"
25-
echoSwagger "github.com/swaggo/echo-swagger"
2625
)
2726

2827
const (
@@ -74,8 +73,8 @@ func addCustomApis(e *echo.Group, apis []restApi) error {
7473
// @securityDefinitions.apikey ApiKeyAuth
7574
// @in header
7675
// @name Authorization
77-
// @BasePath /
78-
func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOptions) {
76+
// @BasePath /sqle
77+
func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOptions, swaggerYaml []byte) {
7978
defer close(exitChan)
8079

8180
e := echo.New()
@@ -99,7 +98,13 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti
9998
}
10099
}
101100

102-
e.GET("/swagger/*", echoSwagger.WrapHandler)
101+
e.GET("/swagger_file", func(c echo.Context) error {
102+
return c.JSON(http.StatusOK, struct {
103+
Content []byte `json:"content"`
104+
}{
105+
Content: swaggerYaml,
106+
})
107+
})
103108

104109
v1Router := e.Group(apiV1)
105110
v1Router.Use(sqleMiddleware.JWTTokenAdapter(), sqleMiddleware.JWTWithConfig(dmsV1.JwtSigningKey), sqleMiddleware.VerifyUserIsDisabled(), sqleMiddleware.OperationLogRecord(), accesstoken.CheckLatestAccessToken(controller.GetDMSServerAddress(), jwtPkg.GetTokenDetailFromContextWithOldJwt))

sqle/docs/docs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14691,7 +14691,7 @@ type swaggerInfo struct {
1469114691
var SwaggerInfo = swaggerInfo{
1469214692
Version: "1.0",
1469314693
Host: "",
14694-
BasePath: "/",
14694+
BasePath: "/sqle",
1469514695
Schemes: []string{},
1469614696
Title: "Sqle API Docs",
1469714697
Description: "This is a sample server for dev.",

sqle/docs/swagger.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"license": {},
88
"version": "1.0"
99
},
10-
"basePath": "/",
10+
"basePath": "/sqle",
1111
"paths": {
1212
"/v1/audit_files": {
1313
"post": {

sqle/docs/swagger.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
basePath: /
1+
basePath: /sqle
22
definitions:
33
controller.BaseRes:
44
properties:

sqle/sqled.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package sqled
22

33
import (
4+
_ "embed"
45
"fmt"
56
"os"
67
"os/signal"
@@ -23,6 +24,9 @@ import (
2324
"github.com/facebookgo/grace/gracenet"
2425
)
2526

27+
//go:embed docs/swagger.yaml
28+
var sqleSwaggerYaml []byte
29+
2630
func Run(options *config.SqleOptions) error {
2731
// init logger
2832
sqleCnf := options.Service
@@ -126,7 +130,7 @@ func Run(options *config.SqleOptions) error {
126130
defer jm.Stop()
127131

128132
net := &gracenet.Net{}
129-
go api.StartApi(net, exitChan, options)
133+
go api.StartApi(net, exitChan, options, sqleSwaggerYaml)
130134

131135
killChan := make(chan os.Signal, 1)
132136
// os.Kill is like kill -9 which kills a process immediately, can't be caught

vendor/github.com/swaggo/echo-swagger/.travis.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

vendor/github.com/swaggo/echo-swagger/LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

vendor/github.com/swaggo/echo-swagger/README.md

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)