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

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() {

EngineerCMS用beego实现swagger API自动化文档_第1张图片

EngineerCMS用beego实现swagger API自动化文档_第2张图片 4.疑问

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

 

你可能感兴趣的:(golang,beego)