beego和bee的安装、自动生成API框架

来源:互联网 发布:现货原油行情软件下载 编辑:程序博客网 时间:2024/04/28 22:36

beggo是一个使用 Go 的思维来帮助您构建并开发 Go 应用程序的开源框架。

一、主要有以下几个特性:

1、简单化

RESTful 支持、MVC 模型,可以使用 bee 工具快速地开发应用,包括监控代码修改进行热编译、自动化测试代码以及自动化打包部署。

2、智能化

支持智能路由、智能监控,可以监控 QPS、内存消耗、CPU 使用,以及 goroutine 的运行状况,让您的线上应用尽在掌握。

3、模块化

beego 内置了强大的模块,包括 Session、缓存操作、日志记录、配置解析、性能监控、上下文操作、ORM 模块、请求模拟等强大的模块,足以支撑你任何的应用。

4、高性能 

beego 采用了 Go 原生的 http 包来处理请求,goroutine 的并发效率足以应付大流量的 Web 应用和 API 应用,目前已经应用于大量高并发的产品中。

bee 工具是一个为了协助快速开发 beego 项目而创建的项目,您可以通过 bee 快速创建项目、实现热编译、开发测试以及开发完之后打包发布的一整套从创建、开发到部署的方案。

二、beego、bee的安装

安装之前首先要保证你已经成功安装go、git工具

1、进入%GOPATH%目录,执行go get github.com/astaxie/beego

2、执行go get github.com/beego/bee  安装bee工具

三、使用bee工具自动创建代码

打开doc窗口,进入到%GOPATH%

bee api基本语法

usage: bee api [appname]create an api application base on beego frameworkbee 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 :8080157888 bytes downloaded.start to unzip file from swagger.zip to swaggerStart delete src file swagger.zip

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

这时候已经自动生成了每个表的增删改查api,可以根据实际需要修改即可。

例如:

http://127.0.0.1:8080/v1/bar/
就可以访问GET方法了


beego为开发者提供了丰富是api文档,可以通过以下url访问:

http://127.0.0.1:8080/swagger/swagger-1/





0 0
原创粉丝点击