beego mysql 生成_beego的文档生成-Go语言中文社区

$(function () {

window.swaggerUi = new SwaggerUi({

url: "http://127.0.0.1:8090/docs",

dom_id: "swagger-ui-container",

supportedSubmitMethods: ['get', 'post', 'put', 'delete'],

onComplete: function(swaggerApi, swaggerUi){、

因为跑到这个端口不是默认的8080,然后就修改下

5648

5648

按照目前的情况来看,文档中需要自己增加的注释,在自己编写的函数中,还是要自己增加,如果是通过ormapping 产生的接口应该是不需要的。

Two solutions

Integrate swagger into the application. Download swagger and put it into project folder. (bee run -downdoc=true will also download it and put it into project folder)

And before beego.Run() in func main() of main.go

if beego.RunMode == “dev” {

beego.DirectoryIndex = true

beego.StaticDir["/swagger"] = "swagger"

}

And then visit swagger document from API project’s URL and port.

Make API support CORS

ctx.Output.Header("Access-Control-Allow-Origin", "*")

Other problems. This is a feature used in my own project. If you have some other problems please fire issues to us.

至于跨域的代码加到什么地方,还不确定?

可能出现的状况包括:

1、swagger目录,ui文件路径,需要和docs并列的目录层次

2、swagger中index 代码引入用的 docs/路径需要确保正确

3、bee run -downdoc=true -gendoc=true

这个命令有意思的-downdoc=true 就是去github下载这个swaggger目录,这个本地可以相互来复制去的。

==

The Configurations for Different Environments

You can set configurations for different runmode under their own sections. Beego will take the configurations of current runmode by default. For example:

appname = beepkg

httpaddr = “127.0.0.1”

httpport = 9090

runmode =“dev”

autorender = false

recoverpanic = false

viewspath = “myview”

[dev]

httpport = 8080

[prod]

httpport = 8088

[test]

httpport = 8888

The configurations above set up httpport for dev, prod and test environment. Beego will take httpport = 8080 for current runmode “dev”.

To get the config under different runmode, you can use “runmode::key”. Such as beego.AppConfig.String("dev::mysqluser")

For custom configs, you need to use beego.GetConfig(typ, key string) to

get the config. (1.4.0+).

支持不同 code run mode,是非常有实际意义的!

RunMode

The application mode, which can be dev, prod or test, dev by

default. In dev mode it will show user friendly error pages as we saw

before but user friendly error pages will not be rendered in prod mode.

beego.BConfig.RunMode = "dev"

RouterCaseSensitive

Set whether the router is case-sensitive or not. Default value is true.

beego.BConfig.RouterCaseSensitive

= true

Also you can change the port it listens on:

AdminHttpAddr="localhost"AdminHttpPort=8088

Open browser and visit http://localhost:8088/ you will see Welcome

to Admin Dashboard.

修改后需要重启 app!!! bee run

live monitor

2016/04/28 23:28:31[parser.go:61][I] /Users/binlu/mycode/golang/src/binlu/apiproject/controllers no changed

2016/04/28 23:28:31[asm_amd64.s:1998][I] http server Running on :8090

2016/04/28 23:28:31[asm_amd64.s:1998][I] Admin server Running on :8088

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值