Beego框架使用
go get github.com/astaxie/beego
vim hello.go
package main import "github.com/astaxie/beego" func main() { beego.Run() }
编译运行
go build -o hello hello.go
./hello
例子2:
package main import ( "github.com/astaxie/beego" ) type MainController struct { beego.Controller } func (this *MainController) Get() { this.Ctx.WriteString("hello world") } func main() { beego.Router("/", &MainController{}) beego.Run() }
编译运行
go build -o hello hello.go
./hello
例子3:
package main import ( "github.com/astaxie/beego" ) type MainController struct { beego.Controller } type UserController struct { beego.Controller } func (this *MainController) Get() { this.Ctx.WriteString("hello world") } //Get方法 func (this *UserController) Get() { this.Ctx.WriteString("hello world222") } type IndexController struct { beego.Controller } //模版使用index.tpl要位于views文件夹下面 func (this *IndexController) Get() { this.Data["Website"] = "beego.me" this.Data["Email"] = "astaxie@gmail.com" this.TplNames = "index.tpl" } func main() { beego.SetStaticPath("/down1", "download1") beego.Router("/", &MainController{}) beego.Router("/user", &UserController{}) beego.Router("/index", &IndexController{}) beego.Run() }
编译运行
go build -o hello hello3.go
./hello
例子3:
// Beego (http://beego.me/) // @description beego is an open-source, high-performance web framework for the Go programming language. // @link http://github.com/astaxie/beego for the canonical source repository // @license http://github.com/astaxie/beego/blob/master/LICENSE // @authors astaxie package main import ( //相对路径 "./controllers" "github.com/astaxie/beego" //从gopath的src目录来 // "github.com/astaxie/beego/example/beeapi/controllers" ) // Objects // URL HTTP Verb Functionality // /object POST Creating Objects // /object/<objectId> GET Retrieving Objects // /object/<objectId> PUT Updating Objects // /object GET Queries // /object/<objectId> DELETE Deleting Objects func main() { beego.RESTRouter("/object2", &controllers.Object2Controller{}) beego.RESTRouter("/object", &controllers.ObjectController{}) beego.Run() }
编译运行
go build -o hello hello3.go
./hello
参考:
http://beego.me/
http://beego.me/quickstart
http://studygolang.com/articles/1124
http://www.golangtc.com/t/5461b63a421aa94699000046
http://studygolang.com/articles/1124
Beego框架使用的更多相关文章
- golang学习之beego框架配合easyui实现增删改查及图片上传
golang学习之beego框架配合easyui实现增删改查及图片上传 demo目录: upload文件夹主要放置上传的头像文件,main是主文件,所有效果如下: 主页面: 具体代码: <!DO ...
- Beego 框架学习(一)
Beego官网本身已经整理的非常详细了,但是作为一个学习者,我还是决定自己好好整理一下,这样在后面使用的时候自己对每部分才能非常熟悉,及时忘记了,也可以迅速定位自己要用的知识在哪里.当然也是对官网的一 ...
- 初次使用beego框架
安装beego框架以及bee工具 go get -u github.com/astaxie/beego go get github.com/beego/bee 创建一个新项目 bee new weba ...
- Golang通过git clone beego框架报错 error: while accessing https://github.com/astaxie/beego/info/refs fatal: HTTP request failed package github.com/astaxie/beego: exit status 128
在Centos6.4尝试搭建beego框架,使用git命令clone时报错 # cd .; git clone https://github.com/astaxie/beego /www/projec ...
- Go语言之高级篇beego框架安装与使用
一.beego框架 1.beego框架简介 beego 是一个快速开发 Go 应用的 HTTP 框架,他可以用来快速开发 API.Web 及后端服务等各种应用,是一个 RESTful 的框架,主要设计 ...
- golang的beego框架开发时出现的问题纪录
golang的beego框架开发时出现的问题纪录1.数据库并发时问题:[ORM]2017/02/20 23:44:05 -[Queries/default] - [FAIL / db.Query / ...
- Go beego框架使用笔记(一)
Beego介绍 beego我认为是go初学者比较容易上手的一门MVC Web框架.简单易懂,最重要的一点就是提供了中文文档,这对于我这种英语能力比较差的人来说就是福音. beego的官网上是这么介绍b ...
- Go语言及Beego框架环境搭建
在开始环境搭建之前,我们先一起来看看: Go有什么优势: 不用虚拟机,它可直接编译成机器码,除了glibc外没有其他外部依赖,部署十分方便,就是扔一个文件就完成了. 天生支持并发,可以充分的利用多核, ...
- golang实现无限级菜单(beego框架下)
原文地址 http://www.niu12.com/article/37 golang实现无限级菜单(beego框架下) 数据表如下 -- ---------------------------- ...
- beego框架(golang)学习验证码
beego框架(golang)学习验证码 登录页面使用验证码 路由设置 /beego_admin_template/routers/router.go get请求页面, post验证用户名密码和验证码 ...
随机推荐
- fzu2188 状压dp
G - Simple String Problem Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- [大坑]FFT学习
[大坑]FFT学习 Macros #define fon(i,s) for(int i=0;i<s; ++i) #define fone(i,s) for(int i=0;i<=s;++i ...
- EXT Grid 默认展开所有行
grid.getStore().load({ //默认展开所有行. callback:function() { var expander = grid.plugins[0]; var count = ...
- zend studio安装svn插件
进入zend->Help->Install New Software 输入如下地址: http://subclipse.tigris.org/update_1.8.x 选择subclips ...
- Java 抽象类与oop三大特征
面向对象主要有三大特性:继承和多态.封装. 一.抽象类 在了解抽象类之前,先来了解一下抽象方法.抽象方法是一种特殊的方法:它只有声明,而没有具体的实现.抽象方法的声明格式为: abstract voi ...
- 内存管理_JAVA内存管理
Java虚拟机规范中试图定义一种Java内存模型(Java Memory Model,JMM)来屏蔽各个硬件平台和操作系统的内存访问差异,以实现让Java程序在各种平台下都能达到一致的内存访问效果.那 ...
- mysql-5.6.23-winx64.zip版本安装记录
*操作系统:Win7 64位旗舰版 一.解压至任意目录,此处以“E:\mysql-5.6.23-winx64”为例: 二.设置环境变量:新建变量名 MYSQL_HOME,值为解压的路径 E:\mysq ...
- Effective C++ -----条款32:确定你的public继承塑模出is-a关系
“public继承”意味is-a.适用于base classes身上的每一件事情一定也适用于derived classes身上,因为每一个derive class对象也都是一个base class对象 ...
- 【leetcode】LRU Cache(hard)★
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the fol ...
- 在Eclipse中手动安装pydev插件,eclipse开发python环境配置
最近在学习Python,因为我是做java的,用惯了eclipse,所以就想用eclipse开发python,但是配置开发环境的时候发现按照网上的配置大多不行,而且都是用的在线安装,很垃圾,没办法,自 ...