一、beego框架

1、beego框架简介

beego 是一个快速开发 Go 应用的 HTTP 框架,他可以用来快速开发 API、Web 及后端服务等各种应用,是一个 RESTful 的框架,主要设计灵感来源于 tornado、sinatra 和 flask 这三个框架,但是结合了 Go 本身的一些特性(interface、struct 嵌入等)而设计的一个框架。

参考官网:https://beego.me/docs/intro/

2、beego 的执行逻辑

beego 是一个典型的 MVC 架构,它的执行逻辑如下图所示:

3、beego 项目结构
一般的 beego 项目的目录如下所示:

├── conf
│ └── app.conf
├── controllers
│ ├── admin
│ └── default.go
├── main.go
├── models
│ └── models.go
├── static
│ ├── css
│ ├── ico
│ ├── img
│ └── js
└── views
├── admin
└── index.tpl

从上面的目录结构我们可以看出来 M(models 目录)、V(views 目录)和 C(controllers 目录)的结构, main.go 是入口文件。

4、beego框架安装

go get github.com/astaxie/beego

参考:https://github.com/astaxie/beego

设置GoPATH路径:

5、bee工具

go get github.com/beego/bee

new命令是新建一个Web项目,我们在命令行下执行bee new<项目名>就可以创建一个新的项目。但是注意该命令必段在$GOPATH/src 下执行。

api 命令 是用来创建API应用的。

安装步骤:

#绝对路径,运行:bee

#安装bee
C:\Users\560140>go get github.com/beego/bee #绝对路径,运行:bee
C:\Users\560140>%GOPATH%/bin/bee
Bee is a Fast and Flexible tool for managing your Beego Web Application. USAGE
bee command [arguments] AVAILABLE COMMANDS version Prints the current Bee version
migrate Runs database migrations
api Creates a Beego API application
bale Transforms non-Go files to Go source files
fix Fixes your application by making it compatible with newer versio
ns of Beego
dlv Start a debugging session using Delve
dockerize Generates a Dockerfile for your Beego application
generate Source code generator
hprose Creates an RPC application based on Hprose and Beego frameworks
new Creates a Beego application
pack Compresses a Beego application into a single file
rs Run customized scripts
run Run the application by starting a local development server
server serving static content over HTTP on port Use bee help [command] for more information about a command. ADDITIONAL HELP TOPICS Use bee help [topic] for more information about that topic

# 设置环境变量临时生效

#设置环境变量,临时生效

C:\Users\560140>set PATH=%PATH%;%GOPATH%/bin

#运行bee
C:\Users\560140>bee
Bee is a Fast and Flexible tool for managing your Beego Web Application. USAGE
bee command [arguments] AVAILABLE COMMANDS version Prints the current Bee version
migrate Runs database migrations
api Creates a Beego API application
bale Transforms non-Go files to Go source files
fix Fixes your application by making it compatible with newer versio
ns of Beego
dlv Start a debugging session using Delve
dockerize Generates a Dockerfile for your Beego application
generate Source code generator
hprose Creates an RPC application based on Hprose and Beego frameworks
new Creates a Beego application
pack Compresses a Beego application into a single file
rs Run customized scripts
run Run the application by starting a local development server
server serving static content over HTTP on port Use bee help [command] for more information about a command. ADDITIONAL HELP TOPICS Use bee help [topic] for more information about that topic.

  

6、beego创建项目

创建web项目: bee new WEB

C:\Users\560140>bee new WEB
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v1.10.0
2019/01/29 14:25:14 WARN ▶ 0001 You current workdir is not inside $GOPATH/sr
c.
2019/01/29 14:25:14 INFO ▶ 0002 Creating application...
create D:\GoFiles\src\WEB\
create D:\GoFiles\src\WEB\conf\
create D:\GoFiles\src\WEB\controllers\
create D:\GoFiles\src\WEB\models\
create D:\GoFiles\src\WEB\routers\
create D:\GoFiles\src\WEB\tests\
create D:\GoFiles\src\WEB\static\
create D:\GoFiles\src\WEB\static\js\
create D:\GoFiles\src\WEB\static\css\
create D:\GoFiles\src\WEB\static\img\
create D:\GoFiles\src\WEB\views\
create D:\GoFiles\src\WEB\conf\app.conf
create D:\GoFiles\src\WEB\controllers\default.go
create D:\GoFiles\src\WEB\views\index.tpl
create D:\GoFiles\src\WEB\routers\router.go
create D:\GoFiles\src\WEB\tests\default_test.go
create D:\GoFiles\src\WEB\main.go
2019/01/29 14:25:14 SUCCESS ▶ 0003 New application successfully created!

创建API项目: bee api API

C:\Users\560140>bee api API
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v1.10.0
2019/01/29 14:25:32 WARN ▶ 0001 You current workdir is not inside $GOPATH/sr
c.
2019/01/29 14:25:32 INFO ▶ 0002 Creating API...
create D:\GoFiles\src\API
create D:\GoFiles\src\API\conf
create D:\GoFiles\src\API\controllers
create D:\GoFiles\src\API\tests
create D:\GoFiles\src\API\conf\app.conf
create D:\GoFiles\src\API\models
create D:\GoFiles\src\API\routers\
create D:\GoFiles\src\API\controllers\object.go
create D:\GoFiles\src\API\controllers\user.go
create D:\GoFiles\src\API\tests\default_test.go
create D:\GoFiles\src\API\routers\router.go
create D:\GoFiles\src\API\models\object.go
create D:\GoFiles\src\API\models\user.go
create D:\GoFiles\src\API\main.go
2019/01/29 14:25:33 SUCCESS ▶ 0003 New API successfully created!

  

7、在LiteIDE中打开WEB项目

把WEB项目导入到LiteIDE中

执行项目:

D:\GoFiles\src\WEB>bee run
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v1.10.0
2019/01/29 14:33:35 INFO ▶ 0001 Using 'WEB' as 'appname'
2019/01/29 14:33:35 INFO ▶ 0002 Initializing watcher...
WEB/controllers
WEB/routers
WEB
2019/01/29 14:33:41 SUCCESS ▶ 0003 Built Successfully!
2019/01/29 14:33:41 INFO ▶ 0004 Restarting 'WEB.exe'...
2019/01/29 14:33:41 SUCCESS ▶ 0005 './WEB.exe' is running...
2019/01/29 14:33:41.919 [I] [asm_amd64.s:1333] http server Running on http://:8
080

  

Go语言之高级篇beego框架安装与使用的更多相关文章

  1. Go语言之高级篇beego框架之config、httplib、context

    一.httplib 1.配置文件解析 这是一个用来解析文件的库,它的设计思路来自于 database/sql,目前支持解析的文件格式有 ini.json.xml.yaml,可以通过如下方式进行安装: ...

  2. Go语言之高级篇beego框架之模型(Models)

    一.模型(Models) 1.beego-orm的相关特性 支持 Go 的所有类型存储 -轻松上手,采用简单的 CRUD 风格 -自动 Join 关联表 跨数据库兼容查询 允许直接使用 SQL 查询/ ...

  3. Go语言之高级篇beego框架之参数配置与路由配置

    一.参数配置 beego默认会解析当前应用下的conf/app.conf文件 1.1.beego的参数配置 appname = WEB httpport = 8080 runmode = dev 几种 ...

  4. Go语言之高级篇beego框架之日志收集系统

    一.日志收集系统架构设计 图1 图2 二.开发环境 1.安装jdk jdk-8u51-windows-x64.exe 安装目录:C:\Program Files\jdk8 2.安装zookeeper ...

  5. Go语言之高级篇beego框架之layui框架应用

    1.layui前端框架 参考地址:https://www.layui.com

  6. Go语言之高级篇beego框架之配置beego环境

    1.配置beego环境 进入部署目录中 软件部署目录: 把要部署的软件代码,放在src目录下面. 启动项目

  7. Go语言之高级篇Beego框架之爬虫项目实战

    一.爬虫项目 1.爬虫基础 a.网页上面会有相同的数据 b.去重处理 布隆过滤器哈希存储 c.标签匹配: 正则表达式beautiful soup或lxml这种标签提取库 d.动态内容 phantomj ...

  8. Go语言之高级篇beego框架之view

    1.基本语法 go统一使用了{{ 和 }}作为左右标签,没有其它的标签符号. 如果你想要修改为其它符号,可以修改配置文件. 使用.来访问当前位置的上下文 使用$来引用当前模板根级的上下文 2.使用方法 ...

  9. Go语言之高级篇beego框架之controller调用model

    一.controller调用model 开发规范,就该把对数据库的操作写在model文件夹中. 示例: views/main.go package main import ( _ "web/ ...

随机推荐

  1. CSS3选择器02—CSS3部分选择器

    该部分主要为CSS3新增的选择器 接上一篇 CSS(CSS3)选择器(1) 一.通用兄弟选择器: 24:E ~ F,匹配任何E元素之后的同级F元素. div ~ p{ background-color ...

  2. WEP/WPA-PSK密码破解工具aircrack-ng

    WEP/WPA-PSK密码破解工具aircrack-ng   aircrack-ng是Aircrack-ng工具集中的一个工具.该工具主要用于根据已经抓取的.cap文件或者.ivs文件破解出WEP/W ...

  3. flask run方法和run_simple

    1.Flask提供的Web服务器不适合在生产环境中使用 2.run方法启动flask集成的服务器: 例: if __name__ == '__main__': app.run(debug=True) ...

  4. Ubuntu 16.04 安装WPS

    1.下载安装包和缺少的字体 安装包下载[http://wps-community.org/download.html?vl=a21#download](这里下载的是最新的安装包) 缺少的字体下载[链接 ...

  5. HDU.5730.Shell Necklace(分治FFT)

    题目链接 \(Description\) 有\(n\)个长度分别为\(1,2,\ldots,n\)的珠子串,每个有\(a_i\)种,每种个数不限.求有多少种方法组成长度为\(n\)的串.答案对\(31 ...

  6. 【bfs】BZOJ1102- [POI2007]山峰和山谷Grz

    最后刷个水,睡觉去.Bless All! [题目大意] 给定一个地图,为FGD想要旅行的区域,地图被分为n*n的网格,每个格子(i,j) 的高度w(i,j)是给定的.若两个格子有公共顶点,那么他们就是 ...

  7. Loj 10211 sumdiv

    题目描述 求 A^B 的所有约数之和 mod 9901. 首先,我们要求出A的约数之和. 就是把A分解质因数,成为:a1^k1*a2^k2*a3^k2.... 然后约数和就是(a1^0+a1^1+a1 ...

  8. 【转载】EmptyWorkingSet 程序运行内存整清理

    网络上找了很多关于内存整理的文章,不外乎都是使用EmptyWorkingSet来实现.就如下面这段代码. #include "stdafx.h"#include <windo ...

  9. OSX下面用ffmpeg抓取桌面以及摄像头推流进行直播

    参考博客 http://blog.chinaunix.net/uid-11344913-id-4665455.html 在osx系统下通过ffmpeg查看设备 ffmpeg -f avfoundati ...

  10. j.u.c系列(10)---之并发工具类:Semaphore

    写在前面 Semaphore是一个计数信号量,它的本质是一个"共享锁". 信号量维护了一个信号量许可集.线程可以通过调用acquire()来获取信号量的许可:当信号量中有可用的许可 ...