Skip to content

Commit

Permalink
refactor: optimized usage logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hononet639 committed Aug 26, 2022
1 parent 816d4b7 commit 41cf2ce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
9 changes: 4 additions & 5 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use knife4j-front to show the api documents for gin
# Usage
1. Add comments to your API source code
2. Download [Swag](https://github.com/swaggo/swag) for Go by using:
3. Run `swag init -ot json ` in your project directory
3. Run `swag init -ot json` in your project directory
4. Run `go get github.com/hononet639/knife4g`
5. Add router to your gin project
### example:
Expand All @@ -17,13 +17,12 @@ use knife4j-front to show the api documents for gin
)

func main() {
port := "80"
engine := gin.Default()
engine.GET("/doc/*any", knife4g.Handler(knife4g.Config{RelativePath: "/doc", Port: port}))
engine.Run(":"+port)
engine.GET("/doc/*any", knife4g.Handler(knife4g.Config{RelativePath: "/doc"}))
engine.Run(":80")
}
```
6. Visit http://localhost:port/doc/front/index
6. Visit http://localhost/doc/index

# Acknowledgement
Thanks to [knife4j](https://github.com/xiaoymin/swagger-bootstrap-ui)
7 changes: 3 additions & 4 deletions knife4g.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var (

type Config struct {
RelativePath string
Port string
}

type service struct {
Expand All @@ -42,11 +41,11 @@ func Handler(config Config) gin.HandlerFunc {
myTemplate.RelativePath = config.RelativePath
docJsonPath := config.RelativePath + "/docJson"
servicesPath := config.RelativePath + "/front/service"
docPath := config.RelativePath + "/front/index"
docPath := config.RelativePath + "/index"
app9f2e4e4ePath := config.RelativePath + "/front/webjars/js/app.9f299301.js"

s.Url = "http://127.0.0.1:" + config.Port + config.RelativePath + "/docJson"
s.Location = "http://127.0.0.1:" + config.Port + config.RelativePath + "/docJson"
s.Url = "/docJson"
s.Location = "/docJson"
s.Name = "API Documentation"
s.SwaggerVersion = "2.0"
return func(ctx *gin.Context) {
Expand Down

0 comments on commit 41cf2ce

Please sign in to comment.