-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
4 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,7 @@ | ||
# swagger服务 | ||
# swagger | ||
|
||
## 依赖 | ||
## 直接下载包,获取dist目录中的文件,替换index.html即可 | ||
|
||
- [go-frame](https://goframe.org) | ||
https://github.com/swagger-api/swagger-ui/releases | ||
|
||
## 安装构建 | ||
|
||
``` | ||
go mod tidy | ||
gf build main.go | ||
mv bin/linux_amd64/swg /var/www/matrix | ||
mv resource/index.html /var/www/matrix | ||
``` | ||
## 目录结构 | ||
```bash | ||
[root@localhost swagger]# tree | ||
. | ||
├── index.html | ||
├── runtime | ||
│ └── server | ||
│ └── 2021-05-26.log | ||
├── swagger | ||
│ └── swagger.json | ||
└── swg | ||
3 directories, 4 files | ||
``` | ||
## 基于supervisor进程守护 | ||
```ini | ||
[program:swg] | ||
directory=/var/www/matrix | ||
command=/var/www/matrix/swg | ||
user=root | ||
autostart=true | ||
autorestart=true | ||
startsecs=3 | ||
startretries=3 | ||
stderr_logfile=/var/log/supervisor/swg-err.log | ||
stdout_logfile=/var/log/supervisor/swg-out.log | ||
``` | ||
## nginx代理 | ||
```nginx configuration | ||
server { | ||
listen 80; | ||
server_name swagger.domain-example.com; | ||
client_max_body_size 10m; | ||
location / { | ||
proxy_pass http://127.0.0.1:8009; | ||
proxy_read_timeout 30s; | ||
proxy_redirect off; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
} | ||
} | ||
``` | ||
## 如果需要配置swagger密码 | ||
```go | ||
// router/router.go | ||
package router | ||
import ( | ||
"github.com/gogf/gf/frame/g" | ||
"github.com/gogf/gf/net/ghttp" | ||
"github.com/gogf/swagger" | ||
"swagger/app/api" | ||
) | ||
func init() { | ||
s := g.Server() | ||
s.Group("/", func(group *ghttp.RouterGroup) { | ||
group.ALL("/", api.Hello) | ||
}) | ||
s.Plugin(&swagger.Swagger{ | ||
BasicAuthUser: "username-placeholder", | ||
BasicAuthPass: "password-placeholder", | ||
}) | ||
} | ||
``` | ||
## 修改index.html中的内容 |