您的位置:首页 > 编程语言 > Go语言

beego框架利用bee api创建api框架

2014-10-23 18:26 489 查看
首先需要beego框架的环境,若未安装,或者版本太老不具有api功能,请先更新或安装此篇

1.安装好beego环境

2.利用bee api创建

打开doc窗口,进入到项目src目录下。即root。

bee api基本语法

usage: bee api [appname]

create an api application base on beego framework

bee api [appname] [-tables=""] [-driver=mysql] [-conn=root:@tcp(127.0.0.1:3306)/
test]
-tables: a list of table names separated by ',', default is empty, indicating all tables
-driver: [mysql | postgres | sqlite], the default is mysql
-conn:   the connection string used by the driver, the default is ''
e.g. for mysql:    root:@tcp(127.0.0.1:3306)/test
e.g. for postgres: postgres://postgres:postgres@127.0.0.1:5432/postgres


如果默认是mysql数据,那么可以省略-driver。
在doc下输入命令

bee api hello -conn=root:root@tcp(127.0.0.1:3306)/test
就会创建一个hello的api项目

进入hello项目目录,输入运行命令

bee run -downdoc=true -gendoc=true
运行成功出现以下状态

2014/10/23 19:07:29 [I] Running on :8080
157888 bytes downloaded.
start to unzip file from swagger.zip to swagger
Start delete src file swagger.zip


这时候修改内容,都会自动编译运行。

这时候已经自动生成了每个表的增删改查api,可以根据实际需要修改即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: