EngineerCMS用beego实现swagger API自动化文档

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hotqin888/article/details/82818500

1.conf

#开启文档
EnableDocs = true

2.路由route.go

func init() {
	//运行跨域请求
	//在http请求的响应流头部加上如下信息
	//rw.Header().Set("Access-Control-Allow-Origin", "*")
	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
		AllowAllOrigins:  true,
		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
		ExposeHeaders:    []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
		AllowCredentials: true,
	}))
	//自动化文档
	ns :=
		beego.NewNamespace("/v1",
			beego.NSNamespace("/admin",
				beego.NSInclude(
					&controllers.AdminController{},
					// &controllers.CustomerCookieCheckerController{},
				),
			),
			beego.NSNamespace("/wx",
				beego.NSInclude(
					&controllers.ArticleController{},
					&controllers.FroalaController{},
					&controllers.LoginController{},
				),
			),

3.controllers

// @Title get wx artiles list
// @Description get articles by page
// @Param page query string  true "The page for articles list"
// @Success 200 {object} models.GetProductsPage
// @Failure 400 Invalid page supplied
// @Failure 404 articls not found
// @router /getwxarticles [get]
//小程序取得所有文章列表,分页
func (c *ArticleController) GetWxArticles() {

 4.疑问

@Success那里的model不会设置,搞不出来效果

 

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页