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框架使用的更多相关文章

  1. golang学习之beego框架配合easyui实现增删改查及图片上传

    golang学习之beego框架配合easyui实现增删改查及图片上传 demo目录: upload文件夹主要放置上传的头像文件,main是主文件,所有效果如下: 主页面: 具体代码: <!DO ...

  2. Beego 框架学习(一)

    Beego官网本身已经整理的非常详细了,但是作为一个学习者,我还是决定自己好好整理一下,这样在后面使用的时候自己对每部分才能非常熟悉,及时忘记了,也可以迅速定位自己要用的知识在哪里.当然也是对官网的一 ...

  3. 初次使用beego框架

    安装beego框架以及bee工具 go get -u github.com/astaxie/beego go get github.com/beego/bee 创建一个新项目 bee new weba ...

  4. 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 ...

  5. Go语言之高级篇beego框架安装与使用

    一.beego框架 1.beego框架简介 beego 是一个快速开发 Go 应用的 HTTP 框架,他可以用来快速开发 API.Web 及后端服务等各种应用,是一个 RESTful 的框架,主要设计 ...

  6. golang的beego框架开发时出现的问题纪录

    golang的beego框架开发时出现的问题纪录1.数据库并发时问题:[ORM]2017/02/20 23:44:05 -[Queries/default] - [FAIL / db.Query / ...

  7. Go beego框架使用笔记(一)

    Beego介绍 beego我认为是go初学者比较容易上手的一门MVC Web框架.简单易懂,最重要的一点就是提供了中文文档,这对于我这种英语能力比较差的人来说就是福音. beego的官网上是这么介绍b ...

  8. Go语言及Beego框架环境搭建

    在开始环境搭建之前,我们先一起来看看: Go有什么优势: 不用虚拟机,它可直接编译成机器码,除了glibc外没有其他外部依赖,部署十分方便,就是扔一个文件就完成了. 天生支持并发,可以充分的利用多核, ...

  9. golang实现无限级菜单(beego框架下)

    原文地址  http://www.niu12.com/article/37 golang实现无限级菜单(beego框架下) 数据表如下 -- ---------------------------- ...

  10. beego框架(golang)学习验证码

    beego框架(golang)学习验证码 登录页面使用验证码 路由设置 /beego_admin_template/routers/router.go get请求页面, post验证用户名密码和验证码 ...

随机推荐

  1. php5.3 appache phpstudy win7win8win10下 运行速度慢解决办法

         在部署服务器以及本地测试的时候发现了一个奇怪的现象,运行PHP程序的时候非常慢,起先以为是网速的原因,后经本地测试发现速度依旧非常慢,打开一个页面差不多要用时3秒以上,这肯定是不正常的,因为 ...

  2. keepalived和heartbeat区别

    <1>Keepalived使用的vrrp协议方式,虚拟路由冗余协议 (Virtual Router Redundancy Protocol,简称VRRP):Heartbeat是基于主机或网 ...

  3. mac os x安装php7.0和phalcon3.0

    1,安装xampp(with php7.0) 下载地址: https://www.apachefriends.org/download.html 2,安装phalcon3.0 cd ~/git clo ...

  4. Git索引

    原文: http://gitbook.liuhui998.com/7_4.html git中的索引(index)是一个存放了排好序的路径的二进制文件(通常是.git/index), 每一个条目都附带有 ...

  5. [转]Tomcat----Neither the JAVA_HOME nor the JRE_HOME environment variable is defined

    对于使用IDE开发的程序员来讲,并不是所有人都对自己用来吃饭的工具了如指掌.常在阴沟跑,哪能不翻船.为此我把自己使用Tomcat/Eclipse的一些经验教训整理了一下,会陆续的贴出来,也许会帮到和我 ...

  6. struts2 复杂参数封装

    1.1.1    Struts2中封装复杂类型的数据: 封装到List集合: 页面: 商品名称:<input type="text" name="products[ ...

  7. Appium+Robotframework实现Android应用的自动化测试-3:一个必不可少的工具介绍

    万事具备,接下来我们就要开始编写测试脚本了. 不过,有个重要的问题还没有解决.我们知道RobotFramework在web 网页中主要依靠元素的id,name或者xpath来定位页面上的元素,我们依赖 ...

  8. QQ登录类

    2015-3-31 22:02:09 (同一套代码, pc端不能登录, 但是, 手机和平板都可以正常登录.....) 1. 首先是库文件, 登录->授权->token->openid ...

  9. ubuntu vsftp 安装

    1.输入sudo apt-get install vsftpd 回车 这样就安装完毕了,然后去建立一个ftp的帐号,我这里使用的是ftp. 2.输入useradd ftp 回车 输入密码 回车 这样帐 ...

  10. 后台子线程(非主线程)更新UI引起的警告

    一.问题描述 -(void)sendAsynchronousRequest { NSLog(@"%@",[NSThread currentThread]); [SVProgress ...