- Integrated swagger support
Used Swagger UI
// IRouteBuilder app.UseEndpoints(...)
endpoints.UseSwaggerDoc(rb,
swagger.Info{
Title: "YoyoGO 框架文档演示",
Version: "v1.0.0",
Description: "框架文档演示swagger文档 v1.0 [ #yoyogo](https://github.com/yoyofx/yoyogo).",
TermsOfService: "https://dev.yoyogo.run",
Contact: swagger.Contact{
Email: "[email protected]",
Name: "yoyogo",
},
License: swagger.License{
Name: "MIT",
Url: "https://opensource.org/licenses/MIT",
},
},
func(openapi *swagger.OpenApi) {
openapi.AddSecurityBearerAuth()
})
// mvc controller
```golang
// DocumentResponse custom document response
type DocumentResponse struct {
Message string `json:"message" doc:"消息"`
List []DocumentDto `json:"list" doc:"文档列表"`
Success bool `json:"success" doc:"是否成功"`
}
func (controller UserController) GetDocumentList(request *struct {
mvc.RequestGET `route:"/v1/user/doc/list" doc:"获取全部文档列表"`
}) DocumentResponse {
return DocumentResponse{Message: "GetDocumentList", List: []DocumentDto{
{Id: 1, Name: "test1", Time: time.Now()}, {Id: 2, Name: "test2", Time: time.Now()},
{Id: 3, Name: "test3", Time: time.Now()}, {Id: 4, Name: "test4", Time: time.Now()},
{Id: 5, Name: "test5", Time: time.Now()}, {Id: 6, Name: "test6", Time: time.Now()},
}, Success: true}
}