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. bufferedimage 转换成 inputstream并保存文件

    BufferedImage img = removeBackgroud(file);//去除重影 //bufferedimage 转换成 inputstream ByteArrayOutputStre ...

  2. tornado 排程

    https://groups.google.com/forum/#!topic/python-tornado/KEmAg97zUg8 鉴于不是所有人都能跨越GFW,摘抄如下: Scheduled jo ...

  3. phpcms分页用法简介

    PHPCMS分页的用法 前面需要有引用的list,代码如下: {pc:content action="lists" catid="11" order=" ...

  4. curl api create domain

    from: https://adam.younglogic.com/2013/09/keystone-v3-api-examples/ http://docs.openstack.org/develo ...

  5. Linux下VMware虚拟机网卡不能运行在混杂模式解决办法

    转自: http://blog.csdn.net/henulwj/article/details/50347489 问题描述 在Linux如果以普通用户运行VMware Workstations,创建 ...

  6. JS插件之——bootstrap-suggest.js

    今天遇到了一个很牛逼的插件bootstrap-suggest.js 如此好用的搜索提示插件 简直酷毙了 源码下载地址 编写了一个例子,供以后参考 <!DOCTYPE HTML PUBLIC &q ...

  7. Kendo UI

    http://www.cnblogs.com/libingql/category/585455.html http://www.scala-china.net/discuz/forum.php?mod ...

  8. mysql开启binlog

    mysql开启binlog,至于为什么要开启binlog,可以google下. ## 设置server_id,一般设置为IP server_id= ## 复制过滤:需要备份的数据库名,多个库以逗号分隔 ...

  9. Java GUI学习笔记之初识AWT和Swing

    Frame f = new Frame(); //获取显示器的尺寸 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize() ...

  10. cocos2dx 2.x实现闪电效果(贴画版)

    cocos2dx 2.x实现闪电效果(非画线版) 在网上搜索到一个直接用opengl画线实现的版本,但放在游戏中效果不太搭,要求用贴图的.我这个版本用的也是画线版的算法. 闪动的时候效果还可以,每段衔 ...