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. python tkinter用Treeview实现ListView效果

    先上图 再上代码: import ttk from Tkinter import * root = Tk() tree = ttk.Treeview(root, columns=('col1','co ...

  2. 开始做POI啦...

    库 为了效率搞了这么一个库: 现在版本号1.14(一月十四日更新版本囧..) http://pan.baidu.com/s/1c0SoGfu [source] http://pan.baidu.com ...

  3. Python 正则表达式:只要整数和小数

    要求用户只能输入数字(包括整数和小数),如何用正则表达式验证用户输入? 有两种思路: 1. 给出正确格式的正则表达式,然后看输入是否合法. 2. 列出所有错误的输入,看输入是否非法. 对于思路1,想想 ...

  4. 百度云+ KeePass 网络同步你的密码

     百度云+ KeePass 网络同步你的密码   百度云一个目前不限流量不限格式能直链的网盘,速度在我这里很快,难得了!KeePass(小众介绍过 KeePass.) 是一个免费开源的密码管理类软件, ...

  5. C#中使用ADOMD.NET查询多维数据集

    ADOMD.NET 是用于与 Microsoft SQL Server Analysis Services 进行通信的 Microsoft .NET Framework 数据访问接口. ADOMD.N ...

  6. Bootstrap datepicker可配置网址

    http://eternicode.github.io/bootstrap-datepicker/?markup=input&format=&weekStart=&startD ...

  7. We7 CMS研究

    我下载的we7 3.0是基于vs 2010的,官方网站也建议使用vs2010,但是我有追新的习惯,并相信vs 2013一定能够兼容vs2010的项目,于是在vs2013下打开解决方案并且全部升级,把目 ...

  8. 从inet_pton()看大小端字节序

    #include<stdio.h> #include<netinet/in.h> #include<stdlib.h> #include<string.h&g ...

  9. log4j:WARN No appenders could be found for logger

    直接写我的解决办法: 在src下面新建file名为log4j.properties内容如下:# Configure logging for testing: optionally with log f ...

  10. Android Volley入门到精通:初识Volley的基本用法

    1. Volley简介 我们平时在开发Android应用的时候不可避免地都需要用到网络技术,而多数情况下应用程序都会使用HTTP协议来发送和接收网络数据.Android系统中主要提供了两种方式来进行H ...