Skip to content

Commit 03ef6f6

Browse files
perf: adjust middleware
1 parent 34e5996 commit 03ef6f6

File tree

30 files changed

+160
-681
lines changed

30 files changed

+160
-681
lines changed

.github/workflows/ci.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
pull_request:
77
branches:
88
- main
9+
workflow_dispatch:
10+
911
permissions:
1012
contents: read
1113
jobs:

Makefile

+23-9
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
1-
.PHONY: all lint test deps
1+
.PHONY: all deps golangci-lint
22

3-
DOC_PATH=assets/openapi-ui.umd.js
4-
DOC_URL=https://cdn.jsdelivr.net/npm/openapi-ui-dist@latest/lib/openapi-ui.umd.js
3+
DOC_PATH=pkg/doc/assets/openapi-ui.umd.js
4+
DOC_URL=https://unpkg.com/openapi-ui-dist@latest/lib/openapi-ui.umd.js
55

6-
run-echo:
7-
cd _examples/echo && go run .
6+
all: download lint test
87

9-
all: $(DOC_PATH) lint test
8+
download:
9+
curl -sL -o $(DOC_PATH) $(DOC_URL)
1010

1111
lint:
1212
go fmt ./...
1313
go vet ./...
14-
golangci-lint run ./...
1514

1615
test:
1716
go test -race ./...
1817

1918
deps:
2019
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
20+
21+
golangci-lint:
22+
golangci-lint run ./...
2123

22-
$(DOC_PATH):
23-
curl -sL -o $(DOC_PATH) $(DOC_URL)
24+
run-echo:
25+
cd _examples/echo && go run .
26+
27+
run-fiber:
28+
cd _examples/fiber && go run .
29+
30+
run-gin:
31+
cd _examples/gin && go run .
32+
33+
run-gorilla:
34+
cd _examples/gorilla && go run .
35+
36+
run-http:
37+
cd _examples/http && go run .

README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
The template is based on the OpenAPI-UI [bundle.js](https://github.com/rookie-luochao/openapi-ui/blob/master/lib/openapi-ui.umd.js) with the script already placed in the html instead of depending on a CDN.
66

7-
This package does not generate openapi spec file. Check [this example](_examples/gen) for using code generation with swag.
7+
This package does not generate openapi spec file. Check [this example](https://github.com/swaggo/swag/tree/master/example) for using code generation with swag.
88

99
## Usage
1010

1111
```go
12-
import "github.com/rookie-luochao/go-openapi-ui"
12+
import "github.com/rookie-luochao/go-openapi-ui/pkg/doc"
1313

1414
...
1515

@@ -27,7 +27,7 @@ doc := doc.Doc{
2727
```go
2828
import (
2929
"net/http"
30-
"github.com/rookie-luochao/go-openapi-ui"
30+
"github.com/rookie-luochao/go-openapi-ui/pkg/doc"
3131
)
3232

3333
...
@@ -40,8 +40,8 @@ http.ListenAndServe(address, doc.Handler())
4040
```go
4141
import (
4242
"github.com/gin-gonic/gin"
43-
"github.com/rookie-luochao/go-openapi-ui"
44-
ginopenapiui "github.com/rookie-luochao/go-openapi-ui/gin"
43+
"github.com/rookie-luochao/go-openapi-ui/pkg/doc"
44+
ginopenapiui "github.com/rookie-luochao/go-openapi-ui/pkg/middleware/gin"
4545
)
4646

4747
...
@@ -55,8 +55,8 @@ r.Use(ginopenapiui.New(doc))
5555
```go
5656
import (
5757
"github.com/labstack/echo/v4"
58-
"github.com/rookie-luochao/go-openapi-ui"
59-
echoopenapiui "github.com/rookie-luochao/go-openapi-ui/echo"
58+
"github.com/rookie-luochao/go-openapi-ui/pkg/doc"
59+
echoopenapiui "github.com/rookie-luochao/go-openapi-ui/pkg/middleware/echo"
6060
)
6161

6262
...
@@ -70,8 +70,8 @@ r.Use(echoopenapiui.New(doc))
7070
```go
7171
import (
7272
"github.com/gofiber/fiber/v2"
73-
"github.com/rookie-luochao/go-openapi-ui"
74-
fiberopenapiui "github.com/rookie-luochao/go-openapi-ui/fiber"
73+
"github.com/rookie-luochao/go-openapi-ui/pkg/doc"
74+
fiberopenapiui "github.com/rookie-luochao/go-openapi-ui/pkg/middleware/fiber"
7575
)
7676

7777
...
@@ -82,7 +82,7 @@ r.Use(fiberopenapiui.New(doc))
8282

8383
See [examples](/_examples)
8484

85-
## 致谢
85+
## Thanks
8686

8787
- [go-redoc](https://github.com/mvrilo/go-redoc)
8888

_examples/echo/main.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package main
22

33
import (
44
"fmt"
5+
"os"
6+
57
"github.com/labstack/echo/v4"
68
"github.com/rookie-luochao/go-openapi-ui/pkg/doc"
7-
middleware_echo "github.com/rookie-luochao/go-openapi-ui/pkg/middleware/echo"
8-
"os"
9+
echoopenapiui "github.com/rookie-luochao/go-openapi-ui/pkg/middleware/echo"
910
)
1011

1112
func main() {
@@ -22,7 +23,7 @@ func main() {
2223
}
2324

2425
r := echo.New()
25-
r.Use(middleware_echo.New(doc))
26+
r.Use(echoopenapiui.New(doc))
2627

2728
println("Documentation served at http://127.0.0.1:8000/docs")
2829
panic(r.Start(":8000"))

_examples/fiber/go.mod

-28
This file was deleted.

_examples/fiber/go.sum

-38
This file was deleted.

_examples/fiber/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package main
22

33
import (
44
"github.com/gofiber/fiber/v2"
5-
fiberredoc "github.com/rookie-luochao/go-openapi-ui/fiber"
65
"github.com/rookie-luochao/go-openapi-ui/pkg/doc"
6+
fiberopenapiui "github.com/rookie-luochao/go-openapi-ui/pkg/middleware/fiber"
77
)
88

99
func main() {
@@ -16,7 +16,7 @@ func main() {
1616
}
1717

1818
r := fiber.New()
19-
r.Use(fiberredoc.New(doc))
19+
r.Use(fiberopenapiui.New(doc))
2020

2121
println("Documentation served at http://127.0.0.1:8000/docs")
2222
panic(r.Listen(":8000"))

_examples/gen/Makefile

-5
This file was deleted.

_examples/gen/docs/docs.go

-37
This file was deleted.

_examples/gen/docs/swagger.json

-12
This file was deleted.

_examples/gen/docs/swagger.yaml

-9
This file was deleted.

_examples/gen/go.mod

-42
This file was deleted.

0 commit comments

Comments
 (0)